Category Archives: Script

Display a pop message at the end of a cron job.


Traditionally, when a cron job is finished. You will get a nice email indicating of its status.

Lately, I am quite annoyed by the amount spams that I am getting.

On my Linux laptop, I had it configured with a few cron jobs running in the background monitoring other activities.

Lately, it just flooding my in-box with messages and becoming unmanageable and hard to keep up.

Since, I am only interested to know if something interesting had occurred. There must be a better way than flooding my in-box with emails.

After, some research I found that the notify-send is included with every Linux-Mint installation. It’s quite simple to use and quite customizable and fit the bill perfectly.

Below is a sample on how to use it:

          notify-send –icon=/usr/share/icons/Mint-X/apps/48/gnome-gnibbles.png –expire-time 30000 ‘Oppa’ ‘You do have a life after work! So, go home!’

Advertisements

Scheduling Linux laptop to suspend and re-animate at scheduled time.


I recently created an automate script which search the internet for certain items and email me the search results. It’s currently running on HP Probook and I don’t want to leave the laptop running indefinitely.

So, I created a cron job to run this script to automatically suspend the laptop when there are no interactive user using the system. The script use rtcwake command to suspend the system in memory and it seemed to work pretty nicely.

To use this script, login as root and saving the following to a file /root/scripts/hybernate

#!/bin/bash
SLEEP_DURATION=1800
if [ $# -gt 0 ]; then
SLEEP_DURATION=$1
fi

# Put the laptop to sleep, if no interactive login and wake up later
if [ `who | wc -l` -eq 0 ]; then
/usr/sbin/rtcwake -m mem -s $SLEEP_DURATION
fi

Change the script permissions:

chmod 755 /root/scripts/hybernate

Then add the following line to root crontabs:

# m h dom mon dow command
* * * * * /root/scripts/hybernate 1800 2>/dev/null