mala::home Davide “+mala” Eynard’s website


Perl Hacks: ESSID-dependant networking startup

Problem: you have a laptop, which has to work with different wifi networks. For each one, you need different startup options (ie. you have to start openvpn at work, you have to set encryption at home, you just have to run networking in all other cases). You would like to autodetect the network you're in and run configs accordingly.

Solution: instead of the usual networking startup script, run this one. Then create some scripts inside /etc/nw directory, one for each ESSID network you've specified inside the Perl script and a default one. For instance:


iwconfig eth1 essid wlanHOME
iwconfig eth1 key 917AD823B4EA3395E214BC258B
/etc/init.d/networking start


/etc/init.d/networking start
/etc/init.d/openvpn start


/etc/init.d/networking start

... of course it's not perfect, but it's quite easy to understand and I hope that with the code under your hands you'll be able to create something useful.

Have phun,


Filed under: hacks, perl No Comments

Perl Hacks: Random Wallpaper

Time ago I was searching for a random wallpaper changer for Gnome, but I couldn't find one which was ok for me. These were the features I wanted:

  • it had to be as simple as a random wallpaper changer should be (you know, something like you click and it changes your wallpaper. Oh yes, randomly!)
  • it had to deal not just with the background image (stretching or shrinking it) but also with all the other background properties I'm used to set with Gnome
  • it didn't have to scan a whole directory and get all the pix inside it, but just to select the few images I liked most

Well, I decided to solve the problem myself with a quick and dirty Perl script: It just scans your backgrounds.xml file where your various backgrounds settings are saved, chooses one background randomly and then applies it. Quick? Yes. Dirty? Yes. But most of all working! :-)

How to install:

  • just make sure you have perl installed in your system with the XML::Simple package. For instance, run
    perl -MXML::Simple -e 'print "Everything ok.n"'

    on your command line and if the answer is "Everything ok" then... well, I suppose everything is ok! Otherwise, you should install XML::Simple package using CPAN. What? You don't know how to do it? Go and learn it! A hint?

    perl -MCPAN -e 'install XML::Simple'
  • download the script and modify it so it matches your home backgrounds.xml file location (a hint: start changing the $HOME path)
  • make sure you have at least two backgrounds configured within Gnome
  • run the script from the command line:

If everything works fine, you can customize it in many ways:

  • make it run automatically at system startup or every few minutes
  • put a new icon on the panel and make it executable with one click
  • create many backgrounds.xml and pass them as parameters, so you have different wallpaper pools to choose from
  • unleash your imagination :)
Filed under: hacks, perl 1 Comment

Welcome to mala::home


Filed under: blog No Comments