13

As said before we are running more than 500 ubuntu PC's in our company. Often we used to set our company ads as a wallpaper in clients machine. It is difficult for us to change wallpapers in all these machines one by one & also it is difficult for us to execute script in every machine through SSH to change the wallpaper. Is there a way to setup a server like if we change the wallpaper in the server it should be effected in all clients machine. If it is possible, it will save our time and effort. Can anyone help? Thanks in advance..

karthick87
  • 81,947
  • 1
    Does your company have a local site that is only viewed by employees? If so can you not add the script into the site so when the site loads it also loads that script? – freebird Jul 07 '11 at 06:40
  • This question needs to be updated for the dconf tools Ubuntu now uses for backgrounds. – Jjed May 16 '12 at 23:08

5 Answers5

15

Set up a cron job on all machines that executes a script where you check 1 specific place for new images. Sample (untested) script with wget and ftp:

#!/bin/bash
wget -N -r -nH --cut-dirs=2 -t 180 -P /tmp ftp://user:password@name.remoteserver.com/dir/backgroundimage.gif
gconftool-2 --type string --set /desktop/gnome/background/picture_filename /tmp/backgroundimage.gif

Basically the 2nd line needs to be altered to the method you use to manually load the image to the machines. And then set up cron to execute this script to check every hour or once a day for new images.

You could even set it up to fetch a script where that script gets excecuted on the client machine and it then fetches the images and changes the background with gconftool-2. This would allow you to execute more than changing a background.


You can create a cron job with sudo crontab -e. This will show a line similar to this:

# m h  dom mon dow   command

(m minutes, h hour, dom day of month, mon month, dow day of week) and underneath it you could add ...

0 * * * /path/to/executable

or

@hourly     /path/to/executable

to have /path/to/executable run every hour on the hour. Mind you: a script you put in here does not understand the path variable unless you include it. You can put this at the top to include $SHELL and $PATH:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

Otherwise you need to make sure your script uses full path names to execute commands. More info on cron can be found on the Ubuntu wiki.

You can also use the /etc/cron.hourly directory to put a script there that gets run every hour. Example topics regarding the last part: What's wrong with my cron.hourly configuration? and Cron.hourly won't run.

Rinzwind
  • 299,756
4

It may be worth it to install a remote admin framework like puppet. It usually takes some time to properly install and configure it for your network, but once it's there it's quite easy to copy files to all the machines (or just a subset of them), run scripts on them and such.

belacqua
  • 23,120
3

You can make the wallpaper setting mandatory, meaning that users will not be able to customize their background.

In Ubuntu 11.04 and earlier, this command should work:

sudo gconftool-2 --direct --config-source \
xml:readwrite:/etc/gconf/gconf.xml.mandatory --type string --set \
/desktop/gnome/background/picture_filename \ 
"/usr/share/backgrounds/cosmos/blue-marble-west.jpg"

In Ubuntu 11.10 (or any GNOME 3 system), you should be able to do this with:

  1. Create a file /etc/dconf/profile/user with the contents:

    user
    site
    
  2. Make a default setting by creating a file /etc/dconf/db/site.d/background with the contents:

    [org/gnome/desktop/background]
    picture-uri='file:///usr/share/backgrounds/company-wallpaper.jpg'
    
  3. And finally make the default mandatory by creating /etc/dconf/db/site.d/locks/background with the contents:

    /org/gnome/desktop/background/picture-uri
    
  4. dconf settings need to be compiled to work so run sudo dconf update The first time you run this, you'll need to reboot to see the effect. Currently, there's a bug where users will still see the normal Background chooser; it just won't actually change the background.

Combine this solution with something like puppet to propogate this setting to all the computers in your company!

Jeremy Bicha
  • 8,234
  • Interesting solution. Wouldn't he be able to simply host the wallpaper on a shared storage somewhere? Like just a normal website, for instance? I think that would be an almost perfect solution in this case, since that would also make it easy to switch. – Jo-Erlend Schinstad Sep 12 '11 at 03:02
  • @Jo-Erlend a normal website would not work since only file:/// URIs are allowed. I expect that a network server would be fine though as long as the computer is already connected to it. – Jeremy Bicha Sep 12 '11 at 03:12
1

here is my solution for ubuntu 11.10 (or any GNOME 3 system):

#!/bin/bash
wget -N -r -nH --cut-dirs=2 -t 180 -P /tmp ftp://ozolniekuvsk.lv/public/foni/ozvsk.jpg
gsettings set org.gnome.desktop.background picture-uri "file:///tmp/ozvsk.jpg"

there is two logical parts. first get wallpaper, second set wallpaper from downloaded location. simple!

cyxob
  • 11
0

Follow these five steps:

  1. Install the clusterssh tool in centos/ubuntu to get the remote session of multiple systems read more about clusterssh

  2. Create a file named clusterssh.sh in the root directory.
    For example : vim /root/.clusterssh.sh

    #!/bin/bash
    cssh  -l <username> <ip addresses to connnect>
    :wq
    

    Once you get the shell of multiple linux hosts.
    Login into the user.

  3. Copy the wallpaper file using root login
    For example:

    scp root@10.1.0.241:/root/Downloads/wallpaper.jpg(Source)  /home (Destination)
    

    It will prompt for password, give password of source system

  4. Run this command to overcome the “Cannot Display error”

    $export DISPLAY=:0
    

    or

    $export DISPLAY=:1.0
    
  5. Run the below command from user login in which we need to set the wallpaper

    pcmanfm  --set-wallpaper=”/home/wallaper.jpg”
    

    In case that the user is not allowed to set the wallpaper, we need to give sudo permission to that user, use below process.

    Go to #nano /etc/sudoers and below root enter

    Username ALL=/usr/bin/pcmanfm #command location
    

And Boom! here you get the wallpaper on your multiple systems in one hit.