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?

Tyralcori
  • 125
  • 10

2 Answers2

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.

Chris Tompkinson
  • 236
  • 1
  • 2
  • 7
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.

Sven
  • 97,248
  • 13
  • 177
  • 225