Indranil Ganguly Indranil Ganguly - 1 year ago 89
Bash Question

How to see shell script execution using Cronjob

I am currently running a cron job to schedule my shell script after a particular interval but i am not able to see my shell script execution and the log how can i see it.

Answer Source

You can use the redirection sign (>) in order to redirect the stdout and/or stderr to a log file.

For example:

0 0 * * * /path/to/ > /tmp/shell-script.log 2>&1


  • 0 0 * * * means the script will run every day at midnight
  • /path/to/ - the path of the script
  • > means redirect the stream to a file followed by the redirection sign
  • 2>&1 means

    • File descriptor 1 is the standard output (stdout).

    • File descriptor 2 is the standard error (stderr).

Here is one way to remember this construct (although it is not entirely accurate): at first, 2>1 may look like a good way to redirect stderr to stdout. However, it will actually be interpreted as "redirect stderr to a file named 1". & indicates that what follows is a file descriptor and not a filename. So the construct becomes: 2>&1.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download