Saturday, 9 March 2013

Playing with cronJobs in ubuntu

This post is about cron jobs and how to set them.

Blabbering the current time every hour

First up, make a executable bash file on the desktop (say

#! /bin/bash
espeak 'the time is' && date +%I:%M | espeak --stdin

espeak is a built in text to speech utility of ubuntu.Here I have piped the string 'the time is' and current time (in hours and minutes) into espeak.

Add it to crontab

Fire up the terminal and type

EDITOR='vim' crontab -e

And add the following line to it

*/20 * * * * /home/user/path/to/

mine looks like

* */1 * * * /home/stom/Desktop/

And we are done, this will run the every hour. for more info on how to specify commands in cron tab , visit CronHowto

Changing Desktop background every 20 minutes

I use xubuntu ,so this works on mine. add this to the crontab

*/20 * * * * xfdesktop --reload

xubuntu uses xfce ,if you have a gnome based distro then try this

gsettings set org.gnome.desktop.background picture-uri 'file:///path/to/image'

Cronning up

@yugdom is a twitter bot, which tweets relevant stuff, using tweepy.Here is how it works, a bash file runs the virtual environment necessary for yugdom (containing bs4 and tweepy) and the

#! /bin/bash
source /home/stom/Desktop/apps/twitter_bot/twitter-bot-env/bin/activate;
python /home/stom/Desktop/apps/twitter_bot/;
echo 'Done'

And this bash file is made to rum every 17th minute with the following line in the crontab

*/17 * * * * /home/stom/Desktop/

playing with espeak

espeak is a lovely utility to play around. Check this out

espeak -p 300 -s 200 "hahahahhahahaha"

-p is used to control the pitch and -s for words per minute.
This generates a funny evil flavoured laughter, I love it. I love it so much that I attached this command to the insert key on the key board, so that I can hear it again and again. To know more check out the man pages of date and espeak.

Anomalies in cron tab

Crontab is weird. So weird, while working on it I ran into some anomalies in it, here is a few of them.

This doesn't work

*/20 * * * * ./home/stom/Desktop/ 

while this does

*/20 * * * * /home/stom/Desktop/

Crontab is unable to run two commands in the same line like this

*/1 * * * * espeak 'foo' ; espeak 'bar'


*/1 * * * * espeak 'foo' && espeak 'bar'

Post a Comment