LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   A question on cron (https://www.linuxquestions.org/questions/linux-newbie-8/a-question-on-cron-757553/)

trist007 09-24-2009 01:28 PM

A question on cron
 
I'm logged in as root and I edited crontab with

Code:

crontab -e
and added this line to the crontable

Code:

25 13 24 9 4 * root /usr/bin/echo "sick" > /home/trist007/itworked.txt
at that time I do see that the file itworked.txt is created, however, there data "sick" is not in the file.

What am I doing wrong?

MensaWater 09-24-2009 01:37 PM

cron is likely interpreting these as separate things.

You need to so something like
"/usr/bin/echo sick" > /home/trist007/itworked.txt

lhorace 09-24-2009 01:42 PM

Did you try
Code:

/usr/bin/echo "sick" > /home/trist007/itworked.txt
in the command line and did it work...

I also remember you had to do a redirection, i think

Code:

/usr/bin/echo "sick" > /home/trist007/itworked.txt 2>&1
hope that helps

trist007 09-24-2009 01:42 PM

I understand that the >&1 redirects the output to that variable, but what is the 2 for?

bathory 09-24-2009 01:47 PM

Quote:

25 13 24 9 4 * root /usr/bin/echo "sick" > /home/trist007/itworked.txt
Maybe it's the extra "*" at your crontab entry. You need 5 fields before the command you want to run.

trist007 09-24-2009 01:53 PM

Got it to work with

Code:

52 13 24 9 4 /usr/bin/echo sick > /home/trist007/itworked.txt 2> /dev/null
So what's that 2 for after itworked.txt?
Also, what if i wanted a certain user to execute that would it have been?

Code:

52 13 24 9 4 root /usr/bin/echo sick > /home/trist007/itworked.txt 2> /dev/null

bathory 09-24-2009 02:03 PM

2 is the file descriptor for STDERR, and using it in your crontab means that any errors will go to /dev/null.
If you want a certain user to execute a cronjob, you should create a crontab for that user


All times are GMT -5. The time now is 09:55 PM.