Poll: Your Favorite Scripting Language?

Posted on in Categories Ask nixCraft, C Programming, Linux, Perl, php, Poll, programming, python, Shell scripting, Sys admin, UNIX last updated April 22, 2009

Like most sys admin, I’m lazy. I try to automate almost all things in order to save time. Inexperienced sys admin and help desk staff working under me finds all these tools useful. It saves their time and avoids security issues. Automation allows help desk staff to do things that they don’t have enough direct system knowledge to do themselves. However, selecting correct tool and applying correct methodology is very important.

Note: There is a poll embedded within this post, please visit the site to participate in this post’s poll.

Humor: Writing Web Service and Pages using Bourne Shell

Posted on in Categories Howto, Humor, Shell scripting, Tips last updated November 22, 2007

Why should shell languages be the only ones left out of the ${YOUR_LANGUAGE_HERE} Server Pages fad? This document chronicles foray into the not-so-fascinating world of ${YOUR_LANGUAGE_HERE} Server Pages technology. All of the code developed is available for free download, so you can use Bourne Shell Server Pages to build your very own killer Web application.

=> Bourne Shell Server Pages [hyperrealm.com]

Run a perl or shell script cron job on the first Monday or the Nth weekday of the month

Posted on in Categories Howto, Linux, Shell scripting, Sys admin, Tips, UNIX last updated July 5, 2007

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.

See also: