1.

Solve : Please help me with crontab command?

Answer»

Hello everybody, I´m here again with other problem.
I have been fighting three days vs crontab command in my Suse 8.1 Linux machine.
The question is I must do a crontab file to execute the order "echo HAPPY BIRTHDAY" each half hour between 9 am and 5 pm the days: may 9, may 14 and august 23.

Well, thus I opened my bash shell and wrote in it:

user > cat > tperiod1 //(The crontab file name).
> * 9,17 9,14 may * echo "HAPPY BIRTHDAY"
> * 9,17 23 aug * echo "HAPPY BIRTHDAY"
> // (ctrl+d)
user > // (this is a prompt)

Once written the file I followed:
user > crontab tperiod1
user >
user > crontab -l

(system answered the file is working, but this is not true in reality)

And for testing that so called "crontab file" I wrote another crontab file more in my bash shell:

user > cat tperiod2
> 1/2 * * * * echo "HAPPY BIRTHDAY"
>
user >
user > crontab tperiod2
user >

And I thought in 30 seconds a message would be displayed: HAPPY BIRTHDAY... but no.

I tested:

user > crontab -l

and Linus system says tperiod2 is running (but it´s not true because there are no messages).

Well, I have tried and tried, I have visited a lot of web pages about crontab command moreover "man crontab", and I am desperated now because I feel myself like a real unfit for this...

Somebody could explain me how building a crontab file step by step, please?

Early thanks ...



When I'm using crontab, I always edit the /etc/crontab file. I like to have all my automation in one place. As root, do vi crontab or whatever editor you prefer. (I use joe, but you may not have it installed.) For your problem I think you should use a different crontab line for each day you want the command to happen.

As for the command itself, I am not convinced this will do anything useful. Cron runs whether or not anyone is logged on. SO where will the echo command send its output? Which terminal? No it would make more sense for cron to email a Happy Birthday message or use write to send the output to a user's tty. Even better, write a script to test whether the user is logged in. If so, use write. If not, use mail. Then run that script from crontab.

Put user-defined scripts in /usr/local/bin, or in ~username/bin.Hi Robpomeroy.
Thanks for your help, like always... I think I have not explained well the problem.
The problem is I must build the file named tperiod1, that must echo a HAPPY BIRTHDAY in my bash console. Nothing about editing the crontab file in /etc/crontab...

Looking other web pages about crontab I have seen something like this, (but I haven´t test it):

user /> cat > tperiod1 //(The crontab file name).
/> /bash/sh // (this is a new line I think to change the execution down sh shell)
/> * 9,17 9,14 may * echo "HAPPY BIRTHDAY"
/> * 9,17 23 aug * echo "HAPPY BIRTHDAY"
/> // (ctrl+d)
user /> // (this is a prompt)

And after this, I think test again:

user /> crontab tperiod1
user />

What do you think about this?

Again, I repeat: where is cron going to send its output? Not to the console. Cron is not attached to a console - it runs independently. The output of the cron JOB you have set up will go (if anywhere) to the system log - normally at /var/log/messages. Load up /var/log/messages, and search for "cron" - you'll probably see your Happy Birthday message appearing there.

This is not the way to achieve what you are trying to do - you must read and understand my first post in this thread.Ok, thanks again for your response. I think I´m going bit a bit understanding how cron works.
But I must imagine what my teachers want I make to response his question (make a crontab file that displays HAPPY BIRTHDAY) and I must join all you have said me about cron and crontab.

Now I´m trying learn about the VI editor, because this is other thing my teachers thinks I ALREADY know for the Holy Ghost´s grace... :-?Yes, because I´m a little bit mind dispersed, I have seen the /var/spool/mail/user, and I had a lot of mails saying HAPPY BIRTHDAY...

Well, thus, I think now I must send the output of this crontab file to /dev/pts/1 (my bash console).

I need a bit of time to do a new experimental file crontab...

And I will return here to say if it works or not.
If you're just going to send it to the console, use the write command. That'll be much easier for you. As I said before, you'd need to test whether the user is logged on. The mails are because CERTAIN distros will automatically email the output of cron jobs to the owner of the job.This is the final solution:

PRACTICE 1st.-
[emailprotected]> who am i
linux!user pts/(number) (date)

[emailprotected]> cat > happybirth
> 5,10,15,20,25,30,35,40,45,50,55 * * * * echo "HAPPY BIRTHDAY" > /dev/pts/(number of who am i)
> (ctrl+d)
[emailprotected]>
[emailprotected]> crontab happybirth
[emailprotected]>

And each five minutes, bash will show you the message HAPPY BIRTHDAY...

This runs on my bash console.

Please Robpomeroy try to do it and tell me... your comments... please.
Thanks.
As soon as you log off, what is going to happen? Cron will start sending emails every five minutes. And then when you log on again? You will only see the messages if you get the same pts terminal. In fact someone else might log onto that terminal and be plagued by the message instead.

But apart from that, it looks like it will do what you want. Just not sure why you would want to do it this way.I don´t logoff my bash console. My bash console is opened.
Each five minutes in bash console appears:

[emailprotected]> HAPPY BIRTHDAY //(MINUTE INIT)
[emailprotected]> HAPPY BIRTHDAY //(MINUTE INIT + 5)
[emailprotected]> HAPPY BIRTHDAY //(MINUTE INIT+10)
[emailprotected]> HAPPY BIRTHDAY //(MINUTE INIT+15)

AND SO ON...

Doesn´t start sending emails.... only sending the message to konsole (bash).

This is what I wanted, and what I was asking here, to see crontab working whatever manner.

I think this is the best example to see how crontab works. I haven´t could find it in the whole Internet.

After this I am ready to make any crontab file with inner commands to execute.

Thanks a lot for all your support.

Glad you got it working the way you wanted!Hi Robpomeroy:
Only is to saying you I just started to study shell scripts today.

I count on you for next help in my Linux problems.

Thanks.



Discussion

No Comment Found