The Blue Screen of Death (BSoD) is used by Microsoft Windows, after encountering a critical system error. Linux / UNIX like operating system may get a kernel panic. It is just like BSoD. The BSoD and a kernel panic generated using a Machine Check Exception (MCE). MCE is nothing but feature of AMD / Intel 64 bit systems which is used to detect an unrecoverable hardware problem. MCE can detect:
- Communication error between CPU and motherboard.
- Memory error – ECC problems.
- CPU cache errors and so on.
[click to continue…]
This is a classic problem. One of our FAQ is about cron job. I received lots of email with a question:
How do I run my script on 3rd Monday or 4th Friday only?
Cron does not offer this kind of facility i.e. you cannot run a script on the Nth weekday of the month.
However with one shell liner you can force to run a script on a given day:
Consider following date command, it will print day:
$ date +%a
You can compare output with weekday name using bash test [exrp ] syntax and the control operators && (AND list), you can write:
$ [ $(date '+%a') == 'Thu' ] && echo 'Today is Thu, run a command' || echo 'Noop'
First echo command get exectued only on Thursday. Now all you have to do is write a cron job to execute on first Monday:
# crontab -e
Now append code as follows:
# Run a script called myscript.sh on First Monday at 11:30:
30 11 1-7 * Mon [ "$(date '+%a')" == "Mon" ] && /path/to/myscript.sh
Hope this small tip will save your day. Please do share some of your favorite bash / shell scripting hacks in the comments. I will highlight some of the best in next shell scripting post.