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
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
crontab -e
add an entry
0 10 * * * sh your_script.sh > your_log_file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With