I have a fairly simple shell script (foo.sh
) that looks like this:
#!/bin/bash
echo -n "$USER,$(date)," `binary -flags | sed -e '1,30d'`;
exit 0;
This script is supposed to prepare some output which will then be appended to a text file, like so:
foo.sh >> data.csv
When I run the above on a root prompt, it works fine. However, when I type the exact same command into my (root) crontab which looks like this:
05 * * * * /root/foo.sh >> /path/to/data.csv
The crontab output differs! I wasn't expecting this and I can't understand why. See examples below:
Expected, normal output from running my .sh (example):
Fri Jun 14 16:32:34 CEST 2013,20130614163304,268828672,71682561
The output written to the file by cron:
Fri Jun 14 16:32:34 CEST 2013,
The rights on the binary run in the .sh looks like this:
-rwxr-xr-x 1 root root
Why does the output differ? How can I get the correct output into my CSV file?
PATH
in the crontab. – jordanm Jun 14 '13 at 15:53