Question

I have a script that I need to schedule on daily basis. How can I schedule a script in centos. Like I want to run that script everyday at 10 AM and can I store the output of the script in a log file.

How to achieve this?

Thanks

Was it helpful?

Solution

To schedule a script, you'll need to use crontab. You can add a schedule entry by doing:

crontab -e

Once you are inside, the cron accepts pattern in the form:

<Minute> <Hour> <Day> <Month> <Day of Week> <Command>

So a correct crontab entry for 10am would be

0 10 * * * /path/to/script

If you want to capture the output you can specify the logfile inside cron like

0 10 * * * /path/to/script > /path/to/log/output.log

Just ensure you put a she-bang header in your script. Alternatively, you can specify the shell interpreter inside cron by saying:

0 10 * * * bash /path/to/script > /path/to/log/output.log

OTHER TIPS

crontab -e

add an entry

0 10 * * * sh your_script.sh > your_log_file
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top