Archive for the 'UNIX' Category

Self-contained crontab Cheatsheet

This time I’m bringing you a self-documented cron table file (with an example), that is, a tidy cheatsheet diagram embedded as comments that does just one thing, helps you remember the crontab syntax:

# * * * * * command to be executed
# - - - - -
# | | | | |
# | | | | +- - - - day of week (0 - 6) (Sunday=0)
# | | | +- - - - - month (1 - 12)
# | | +- - - - - - day of month (1 - 31)
# | +- - - - - - - hour (0 - 23)
# +- - - - - - - - minute (0 - 59)

# Alarm clock set to 6:30AM
30 6 * * * /home/nano/alarm

I hope you find it useful, thanks for reading and happy May Revolution Day to everyone!

UNIX Programming: Simple Notifications With mailx

Hey there! I know it’s been a month since my last post, I’m sorry about that but I’ve been pretty busy this days, having a lot to do at work and also being a full time student, so anyway, this time I’m sharing with you a nifty tip regarding notifications using mailx on UNIX, so without further ado, here’s the actual code:

#!/bin/ksh
#
# mailx settings:
#
to="someone@somewhere.com"
subject="[Notification] Something happened."
body="Lorem ipsum dolor sit amet et cétera."
#
# run and notify:
#
runSomething && (echo $body | mailx -s "$subject" "$to")

I hope you find it interesting, thanks much for reading and don’t hesitate to leave a comment!

Checking For Duplicated Processes In Korn Shell

A couple of days ago I was needing to solve an issue with our EAI framework. The implementation of such framework could be basically described as instances of Java programs running under Solaris, but there’s a particular instance that should be running just once. So I wrote this tiny shell script to avoid launching that program twice:

#!/bin/ksh
#
theProcess=someProcess
if [ $(pgrep -u $USER -f $theProcess | wc -l) -gt 0 ] then
echo "There is an instance of "$theProcess" already running."
else runTheProcess
fi

someProcess could be any regex that matches the process description,
runTheProcess is whatever command that executes the process.
Okay, that’s all, I hope you’ve found it informative and thanks for reading!