Results 1 to 6 of 6
I want to write the date & time and a text string to a file from crontab.
The following line works fine in the CL:
echo $(/bin/date +"%F %T")" Some ...
- 07-16-2010 #1Just Joined!
- Join Date
- Jul 2010
- Posts
- 3
cmd works in bash, not crontab??
I want to write the date & time and a text string to a file from crontab.
The following line works fine in the CL:
echo $(/bin/date +"%F %T")" Some text" >> /home/me/foo.txt
I installed in crontab and no text appears in the file that it is redirected to.
The crontab entry looks like:
* * * * * echo $(/bin/date +"%F %T")" Some text" >> /home/me/foo.txt
Tried a version to just write to stdout....
* * * * * echo $(/bin/date +"%F %T")" Some text"
No date, time or text appears at the command line, nada.
Shell is bash.
Any suggestion what the problem is and how to fix???
thanks,
-J
- 07-16-2010 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
You might want to run the command with nohup instead. Some applications will barf if they aren't attached to some sort of terminal for all of stdin, stdout, and stderr.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 07-16-2010 #3Linux User
- Join Date
- Nov 2009
- Location
- France
- Posts
- 292
Try this :
in your cron file. cron ignores the system's PATH variable. You have to redefine it in the cron file or use absolute paths.Code:/bin/echo
0 + 1 = 1 != 2 <> 3 != 4 ...
Until the camel can pass though the eye of the needle.
- 07-16-2010 #4Just Joined!
- Join Date
- Jul 2010
- Posts
- 3
OK, well I tried nohup, as well as &, and neither command worked...e.g. no text in the target file. Here are the excerpts from crontab:
* * * * * nohup echo $(/bin/date +"%F %T")" From cron" >> /home/me/foo.log&
and,
* * * * * echo $(/bin/date +"%F %T")" From cron" >> /home/me/foo.log&
Not sure I used nohup correctly, but the command worked when entered from the CL.
Good suggestion...am sorry it didn't fix the problem....sigh
-JLast edited by three_jeeps; 07-16-2010 at 05:33 PM. Reason: mistake
- 07-16-2010 #5Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Use single quotes with the date command:
Or escape the % character:Code:$(/bin/date +'%F %T')" Some text" >> /home/me/foo.txt
Code:$(/bin/date +"\%F \%T")" Some text" >> /home/me/foo.txt
- 07-16-2010 #6Just Joined!
- Join Date
- Jul 2010
- Posts
- 3
Resolved!
Using the escape in the date command, in crontab worked:
Interestingly, using the single quotes did not....hmmmCode:* * * * * echo $(/bin/date +"\%F \%T")" Some text" >> /home/me/foo.txt
Thank you!Code:* * * * * echo $(/bin/date +'%F %T')" Some text" >> /home/me/foo.txt
-J


Reply With Quote
