Following commands are made for reference purposes only … zaib
To add scheduled job in linux/ubuntu, use
crontab -eTo view installed cron
crontab -l
Examples:
Run Script after every 5 seconds [Updated 8th Aug, 2016]
I had a UPS monitor script that should run after every 5 seconds to poll the KE input voltage / battery remaining time etc. but as we know that with CRON we can configure interval of minimum 1 minute or above, we cannot set time in seconds. so I make following workaround.
conrtab -e
and added script as follows
# UPMON.SH is my script to monitor UPS # 10.0.0.1 is my UPS network card * * * * * /temp/upsmon.sh 10.0.0.1 * * * * * sleep 5; /temp/kemon.sh 10.0.0.1 * * * * * sleep 10; /temp/kemon.sh 10.0.0.1 * * * * * sleep 15; /temp/kemon.sh 10.0.0.1 * * * * * sleep 20; /temp/kemon.sh 10.0.0.1 * * * * * sleep 25; /temp/kemon.sh 10.0.0.1 * * * * * sleep 30; /temp/kemon.sh 10.0.0.1 * * * * * sleep 35; /temp/kemon.sh 10.0.0.1 * * * * * sleep 40; /temp/kemon.sh 10.0.0.1 * * * * * sleep 45; /temp/kemon.sh 10.0.0.1 * * * * * sleep 55; /temp/kemon.sh 10.0.0.1 * * * * * sleep 60; /temp/kemon.sh 10.0.0.1this way the script will run and wait for five seconds before next execution. 🙂 lalalala / zaib
Run Script after every 2 hours (daily basis* it helped me very much)
0 */2 * * * /temp/script.sh
Run Script at Every 1st day of Month [Every Month]
@monthly /temp/script.sh
Run Script on 1-am on every Monday
0 1 * * MON /temp/xdrive_noupdate.sh
Run Script Daily at 00:00 hours (midnight)
@daily /temp/script.sh
Run Script Daily at 09:00 hours (Morning 9am)
# m h dom mon dow command
00 09 * * * /temp/fullbackup.sh
Run Script every hour
@hourly /temp/script.sh
Run Script every minute
* * * * * /temp/script.sh
Run Script after every 5 minutes
*/5 * * * * /temp/script.sh
Run Script on Specific Timings And Date of Months, Example run script on 10am and 11am on 12th of every month.
00 10,11 12 * * /temp/script.sh
Run Script on Specific Hours of Every Month, Example run script on 9am of every month.
00 9 10 * * /temp/script.sh
Run Script on Specific Hours RANGES , Example run script on 10am to 8pm , means every hour from 10am-8pm
00 10-20 * * * /temp/script.sh
Shortcuts in CRON
@reboot Run once, at startup. @yearly Run once a year, "0 0 1 1 *". @annually (same as @yearly) @monthly Run once a month, "0 0 1 * *". @weekly Run once a week, "0 0 * * 0". @daily Run once a day, "0 0 * * *". @midnight (same as @daily) @hourly Run once an hour, "0 * * * *".
Scheduled CON Job running but not producing results …
[Monday 27th Feb,2017]
I scheduled few scripts on my Ubuntu 14.x box that queries remote servers for storage and send customized reports via email. I can see its execution in /var/log/syslog but the script was not able to query the remote win server.
To solve it I had to add the PATH command in the script , sample as below…
#!/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binThis solved my issue 🙂
These are little things that you learn on daily basis ,
One very useful crontab demonstration to check errors or make cron
Run script after X minute (just one time only, without using cron)
echo YOUR-SCIPT.SH | at now + 1 minute
Disabling CRON job Emails!
You may want to read this.
https://aacable.wordpress.com/2018/06/08/disabling-email-for-cron-jobs/
Regard’s
Syed Jahanzaib