LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-24-2009, 02:28 PM   #1
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,027

Rep: Reputation: 69
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?

Last edited by trist007; 09-24-2009 at 02:42 PM.
 
Old 09-24-2009, 02:37 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,577
Blog Entries: 14

Rep: Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969
cron is likely interpreting these as separate things.

You need to so something like
"/usr/bin/echo sick" > /home/trist007/itworked.txt
 
Old 09-24-2009, 02:42 PM   #3
lhorace
Member
 
Registered: Aug 2009
Distribution: Fedora
Posts: 126

Rep: Reputation: 21
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
 
Old 09-24-2009, 02:42 PM   #4
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,027

Original Poster
Rep: Reputation: 69
I understand that the >&1 redirects the output to that variable, but what is the 2 for?

Last edited by trist007; 09-24-2009 at 02:48 PM.
 
Old 09-24-2009, 02:47 PM   #5
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,519

Rep: Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501
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.
 
Old 09-24-2009, 02:53 PM   #6
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,027

Original Poster
Rep: Reputation: 69
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
 
Old 09-24-2009, 03:03 PM   #7
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,519

Rep: Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 09:16 AM
cron not working from crontab nor form /etc/cron/cron.d. What did SuSE change? JZL240I-U SUSE / openSUSE 11 01-04-2007 02:57 AM
Can any one plz explain why/what for cron.d, cron.daily, cron.weekly etc are there. mavinashbabu Linux - Newbie 4 09-21-2006 02:50 PM
Cron question sketch7 Linux - General 1 09-10-2003 09:03 PM
Cron Question.... bfloeagle Linux - General 3 03-13-2001 11:15 PM


All times are GMT -5. The time now is 08:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration