Search code examples
linuxcroncron-task

How to know that .sh file content is executed in crontab


How to know that .sh file content is really executed in crontab ?

For example : I have created .sh file and pasted a content "ping www.google.com" inside the file.

I can check in /var/logs file that the crontab is executed and details, but, how to know that the file content is really executing or not.


Solution

  • make your script sh log. Something like:

    log_file=/var/log/your_script/you_script.log
    log_mex="bla bla"
    # Other code
    ping google.com
    echo $log_mex $? > /var/log/your_script/you_script.log
    

    or redirect the whole ping error message

    ping google.com 2>$log_file