1

I wrote a shell script with the following content:

#!/bin/bash value=`cat test.txt` echo "Output: $value" >> currentOutput.txt 

By executing this script in shell, it writes correctly the value inside the currentOutput.txt. By executing this script over /etc/crontab, the file only gets filled with "Output:".

The executing user in shell and crontab is root. Also the owner from "currentOutput.txt", "test.txt" and the script is root. I'm just wondering about the different output between normal executing and executing by crontab.

This is my crontab entry:

*/5 * * * * root /bin/sh /var/www/testscript.sh 

Any suggestions?

2 Answers 2

4

try using an absolute path to test.txt, it's unlikely that crontab is using the same local directory as you are when you execute the script and that file may not exist.

0
3

The working directory is most likely not the directory where your file is stored in (e.g. /var/www). Try to specific the full path for test.txt.

You should always be as specific as possible in cron jobs, as the whole environment is quite different to your normal shell environment.

1
  • Also thank you, too! I'll accept the other answer as "correct", because he was 6 seconds faster. Commented Oct 30, 2015 at 10:37

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.