Yanik
Yanik

Reputation: 143

Write from Shellscript to file when running the script from crontab

What I am trying and tried to do:

I've written a Shellscript which should write some logs into a logfile. Something like:

    echo "downloaded header" >> log

I also tried with cat instead of echo and I've given full permissions to the log so it should be accessible for anyone. If I start the script from the command line everything works fine and the entries are made as expected. It didn't matter if I gave the full path to the logfile or not, I tried both.

The Problem:

If I run the script from crontab and yes It has to work with crontab, nothing is written into my log. So the echo "xy" >> log doesn't work, neither does the cat.

Any Ideas? Thanks in advance.

Upvotes: 1

Views: 1034

Answers (2)

MLSC
MLSC

Reputation: 5972

try this solution:

cat cronjob
* * * * * echo "downloaded header" >> /path/to/log

Then:

chmod +x cronjob
chmod +x script.sh

/etc/init.d/crond start  #redhat based servers like centos
/etc/init.d/cron  start  #debian based servers like ubuntu

crontab cronjob

Upvotes: 1

Fidel
Fidel

Reputation: 1037

Try redirecting to the log file with full path

echo "downloaded header" >> $HOME/Log_dir/log  ## just an example

Upvotes: 1

Related Questions