LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 01:28 PM   #1
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,052

Rep: Reputation: 70
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 01:42 PM.
 
Old 09-24-2009, 01:37 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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, 01: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, 01:42 PM   #4
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,052

Original Poster
Rep: Reputation: 70
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 01:48 PM.
 
Old 09-24-2009, 01:47 PM   #5
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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, 01:53 PM   #6
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,052

Original Poster
Rep: Reputation: 70
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, 02:03 PM   #7
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

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



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 08: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 01: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 01:50 PM
Cron question sketch7 Linux - General 1 09-10-2003 08:03 PM
Cron Question.... bfloeagle Linux - General 3 03-13-2001 10:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:31 PM.

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
Open Source Consulting | Domain Registration