1

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.

3
  • Is the filename (after >>) just log, or is it the full path? Commented Feb 19, 2014 at 10:09
  • You need to supply the complete path the log file. Commented Feb 19, 2014 at 10:10
  • Forgot to mention, I also allready tried this and it didn't work. Thank you anyway. I just edited it in my question. Commented Feb 19, 2014 at 10:16

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

1

Try redirecting to the log file with full path

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

1 Comment

Forgot to mention, I also allready tried this and it didn't work. Thank you anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.