Last modified on 12 July 2011, at 14:58

Wallpaper cronjob

Changing the wallpaper every x minutes by using a cronjob

Installing cron

To change the wallpaper in XFCE automatically you need cron. Test if it is already installed by opening a terminal and typing:

crontab -l

If you get "command not found" you need to install it. Remember to activate wifi.

First update your package list:

sudo opkg update

and then:

sudo opkg install cron

Adding pictures

  1. Right-click on your desktop.
  2. Select Desktop settings.
  3. In the tab "Background" select "Image list"
  4. Click on "Create new list / load existing one" (left to "Style" the sheet of paper with the plus-sign)
  5. Enter a path and filename for your list
  6. Add the image files by clicking on the green "+"
  7. Close the window, it saves automatically. If you want, check the file you created, it should contain a list of pictures.

Setting up the cronjob

Right now every time the xfdesktop reloads a picture will randomly be selected from the list. As it only gets reloaded by a reboot (or by manually calling a reload) we need to trigger a reload automatically.

First open a new file in your preferred editor, e.g. vi. Then enter the following linee (I'll later explain why):

# Reload wallpaper every 5 minutes.

*/5 * * * * /usr/bin/xfdesktop --reload --display 0:0

Save it as anything you want, e.g. cron.txt.

In a terminal add the file to the cronjob list:

crontab cron.txt

Now if you call "crontab -l" it should show your entry.

Check if cron is running:

ps aux | grep -i cron

This lists all running processes which contain "cron", case insensitive (-i). This will propably show exactly two processes, something like this:

root 6278 0.0 0.2 1736 648 ? Ss 13:39 0:00 cron

usr7 1337 0.0 0.2 1700 508 pts/1 S+ 15:21 0:00 grep -i cron

That is, the first line shows that cron is running, the second line is your listing of all processes containing "cron", thus listing itself.

If there is no "cron" listed then start it: sudo cron

Now if everything worked you should see your wallpaper changing every 5 minutes.

How it works (simplified)

"crontab cron.txt" adds every line in cron.txt to the list of running jobs. Every minute "cron" checks every entry if it should get executed. The five * are wildcards for the time when a job should be executed. This graphic (borrowed from Wikipedia) shows what they mean:


*    *    *    *    *  command to be executed
┬    ┬    ┬    ┬    ┬
│    │    │    │    │
│    │    │    │    │
│    │    │    │    └───── day of week (0 - 7) (Sunday=0 or 7)
│    │    │    └────────── month (1 - 12)
│    │    └─────────────── day of month (1 - 31)
│    └──────────────────── hour (0 - 23)
└───────────────────────── min (0 - 59)


Also the "/5" means "every 5 units":

*/5 * * * * echo Every 5 minutes

0 */2 * * * echo Every 2 hours at 0 minutes

0 0 */3 * * echo Every 3 days at 00:00

and so on.

So if you want your wallpaper so change every 15 minutes you would use */15.

External Links

Crontab on Wikipedia

Tutorial I used on www.howtoforge.com

Forum thread on boards.openpandora.org