Posts Tagged ‘script’

Start up Sound

15, March 2011

Start up Sound:

This works on my Xubuntu Natty install. I found a .ogg sound file that I wanted to use as a start up sound so needed an command line ogg player to play it.

$ sudo apt-get install ogg123

Now create a script in /usr/bin as follows [replace mousepad with the text editor of your choice];

$ sudo mousepad /usr/bin/startup

Add the following to the file

#### play sound at startup ####
## reduce volume ##
sleep 5
/usr/bin/amixer -c 0 sset Master,0 60%
## play sound ##
/usr/bin/ogg123 /path_to_my/sartupsound.ogg
## increase volume again ##
/usr/bin/amixer -c 0 sset Master,0 85%

save the script and make it executable with.

$ sudo chmod +x /usr/bin/startup

Now add the script to the system start up, in Xubuntu open [Settings], [Settings Manager], [Session and Startup], [Application Autostart], and then the [Add] button. Add a name of your choice in the Name field, and the same in the Description field, then the path to your script in the Command field i.e /usr/bin/startup in this case the [ok] to finish. You will then get a startup sound next time you log on.


1, December 2010

Using the gconf tool to make changes to your desktop from the command line. These allow you to script changes you make every time to upgrade.

These have been tested on the Gnome Desktop on Lynx & Maverick.

Copy and paste these commands into a Terminal [Applications], [Accessories], [Terminal]

## Add icons to the [System] menu. ##
gconftool-2 --type Boolean --set /desktop/gnome/interface/menus_have_icons True

## Remove shutdown “Do you really want to do this 60 second count down” question ##
gconftool-2 --type Boolean --set /apps/indicator-session/suppress_logout_restart_shutdown True

## Return to old Update notification icon in top menu ##
gconftool-2 --type Boolean --set /apps/update-notifier/auto_launch False

gconftool-2 --type int --set /apps/update-notifier/regular_auto_launch_interval 0

## Add Banner message to GDM ##
sudo -u gdm gconftool-2 --set --type string /apps/gdm/simple-greeter/banner_message_text “Ubuntu 10.10 Maverick Meerkat 64 Bit”

sudo -u gdm gconftool-2 --set --type string /apps/gdm/simple-greeter/banner_message_text_nochooser “Ubuntu 10.10 Maverick Meerkat 64 Bit”

sudo -u gdm gconftool-2 --set --type boolean /apps/gdm/simple-greeter/banner_message_enable true

## Set wallpaper ##
gconftool-2 --type string --set /desktop/gnome/background/picture_filename /home/Pictures/My_Wallpaper.jpg

Sheevaplug – automount USB drive at boot

17, February 2010

The problem with the Sheevaplug is that it boots too damn fast and the USB drive is too slow to be available for the fstab mount.

The solution, see here for my post on setting up the fstab file to mount your USB drive. When you edit the fstab on the Sheeva you will find it empty but you should end up with an entry similar to this.

/dev/sda1 /mnt/usbdrive ext3 auto,user,rw,exec 0 0

My usb drive is mounted at /dev/sda1 and I created a mount point called /mnt/usbdrive, the drive is formatted as ext3 but you can replace this with the format of your drive or just replace with the word auto for it to check.

Once you have your fstab in place you need to create a script which will slow down the boot for the USB drive to start. Thanks to restamp on the forum see here for the solution.
First navigate to the init.d folder, in a [Terminal] issue the command;

cd /etc/init.d

then using whatever text editor you have installed [I added nano], open a file called wait4usbdrive with;

nano wait4usbdrive

then copy into it restarts script;

# If /etc/fstab has been configured to mount a USB drive, pause to give
# the USB drive devices time to show up in /dev. If this is not done,
# will fail, requiring manual intervention…
case "$1" in
grep -q ^/dev/sda /etc/fstab &&
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
[ -b /dev/sda ] && exit 0
sleep 1
exit 1

Then make it executable with;

chmod +x wait4usbdrive

Then link it to the rcS.d folder with this command;

ln -s ../init.d/wait4usbdrive /etc/rcS.d/S25wait4usbdrive

Now you can shutdown and restart the plug and the USB drive should now auto-mount. My USB drive is a 1.5 TB iomega with it’s own power supply.

Quake One

13, December 2009

Well it’s been a while since I’ve played this but I finally got it working in Ubuntu Karmic using glquake, the .pak files from my Quake One CD and a script using the info. from this thread at I created a folder called quake_one and within it another called id1, I then copied the .pak files from the CD to the id1 folder making sure their filenames were in lowercase. Then copied the glquake file to the quake_one folder. Now I created a script in my path called with the following in it;

## Update Permissions
sudo chmod 666 /proc/asound/card0/pcm0p/oss
sudo chmod 666 /proc/asound/card0/pcm0c/oss
echo “Permissions changed…”
## change to quake one directory ##
cd ~/quake_one
## redirect quake sound ##
sudo echo “glquake 0 0 direct” > /proc/asound/card0/pcm0p/oss
sudo echo “glquake 0 0 disable” > /proc/asound/card0/pcm0c/oss
## run quake one prog ##

saved it to ~/bin  then made the script executable with;

chmod +x ~/bin/

Now run in a [Terminal] or create a launcher pointing to this script, all done.

Backup using rsync, SSH & cron

31, August 2009

Backup on Ubuntu.

Updated 09/11/09 to correct some errors!

This “How To” was written with the help of this article by Troy Johnson, here and amended were necessary to fit my needs.

I have 2 PC’s on a network and want to backup some files from one PC the [remote_client] to the other PC the [server] to do this I want to run a script from the server. The process can be achieved using rsync & SSH and automated with a cron job on the server.


We install on the server

open-ssh-server and rsync

and on the client openssh-client and rsync

This can be done via the Synaptic Package Manager or using the command line i.e.

~$ sudo apt-get install openssh-client

~$ sudo apt-get install rsync

you also may want to check that cron is installed and if you want a GTK version of rsync you could install gadmin-rsync.

So the files I want to backup are on the remote_client in the following folder; /home/martin/my_files

and I want to back them up on the server in the following folder; /home/martin/backups

Note: I have an account on both PC’s with the same name and password, and read access to both the source & destination folders.

On the server we test out a basic script called and saved with the Permissions set to “allow executing as a program”, check out my post here for help with that, the content of the script is;


## first script to copy files from remote_client to server ##

rsync -avz -e ssh martin@remote_client:/home/martin/my_files/ /home/martin/backups

save the script and then run it by typing;

~$ ./

in a Terminal assuming you saved the script in your home directory /home/martin and called it You should be prompted for your user password on the remote_client then the process should start.


Ok so that does the trick but if I’m to automate this script it needs to work without SSH asking me for my password each time. To do this I need to generate a private/public key pair, this is much more secure than adding the actual password in the text of the script or elsewhere linked to it.

We now need to be logged onto the server;

To generate the key pair I open a [Terminal] and issue the command;

~$ mkdir /home/martin/.key

to create a hidden folder in my home folder called .key [the dot makes it hidden], then;

~$ ssh-keygen -t dsa -b 1024 -f /home/martin/.key/server-rsync-key

Generating public/private dsa key pair.

Enter passphrase (empty for no passphrase): [press Enter]

Enter same passphrase again: [press Enter]

Your identification has been saved in /home/martin/.key/server-rsync-key.

Your public key has been saved in /home/martin/.key/

The key fingerprint is:

etc. etc.

I now have 2 files in the .key folder in my home folder called;



As you will later set-up a cron job which will run a script that needs access to the junk-rsync-key file we need to change the default ubuntu file permissions to owner, read/write group & other to none

$ chmod 600 server-rsync-key

Now copy the other key, over to the remote_client into my home folder /home/martin and log onto the remote_client.

Now on the remote_client, I issue the following command in a [Terminal]

~$ if [ ! -d .ssh ]; then mkdir .ssh ; chmod 700 .ssh ; fi

[this checks to see if the folder .ssh exists and if not creates it]

~$ mv .ssh/

[this moves the key from my home folder to the .ssh folder, hidden in my home folder]

~$ cd .ssh/

[we now move to the .ssh folder]

~$ if [ ! -f authorized_keys ]; then touch authorized_keys ; chmod 600 authorized_keys ; fi

[this checks to see if there is an authorized_keys file and if not creates it with the correct permissions]

~$ cat >> authorized_keys

[this copies the contents of key into the file authorized_keys file.

If we now run our original script with the amendment below on the server it no longer asks for a password.

rsync -avz -e “ssh -i /home/martin/.key/server-rsync-key” martin@remote_client:/home/martin/my_files/ /home/martin/backups


Now the key can be used to make connections to the remote_client, but these connections can be from anywhere (that the ssh daemon on remote_client allows connections from) and they can do anything (that remote_user can do), which could be dangerous.  To make this more secure edit the ‘authorized_keys’ file in remote_client /home/martin/.ssh folder with a text editor and modify the line ending user_name@server_name from this:

nyA7 etc....

to this:

from="", command="/home/martin/.key/validate-rsync" ssh-dss bA402VuCsOLg
nyA7 etc....

where “” is the IP address of server, and “/home/martin/.key/validate-rsync” point to a script called validate-rsync as follows:

echo “Rejected”
echo “Rejected”
echo “Rejected”
echo “Rejected”
echo “Rejected”
echo “Rejected”
echo “Rejected”
rsync\ –server*)
echo “Rejected”

If server has a variable address, or shares its address (via NAT etc.) with hosts you do not trust, omit the ‘from=”″,’ part of the line (including the comma), but leave the ‘command’ portion. This way, only the ‘rsync’ will be possible from connections using this key. Make certain that the ‘validate-rsync’ script is executable by remote_user on remote_client and test it.

So in my case the result looks like this:

command="/home/martin/.key/validate-rsync" ssh-dss bA402VuCsOLg9YS0NKxugT+o4UuIj
nyA7 etc....

Our script now looks like this:


## second script to copy files from remote_client to server ##

rsync -avz -e “ssh -i /home/martin/.key/server-rsync-key” martin@remote_client:/home/martin/my_files/ /home/martin/backups


I now need to run the script from a Cron job, first move the script into your $PATH, for help with this check out my post here.

Now on the server open a [Terminal] and issue the command:

~$ crontab -e

This should open a text editor, normally vi, normally paste into it the following text as a reminder

# leave a space between each option #
# the * is a wildcard option #
# dayofmonth is 1 to 31 #
# dayofweek can be 0 – 6, 0 is Sunday #
# or use mon tue wed etc #
# mins hours dayofmonth month dayofweek command
# * * * * * * command

Then use Crontrol+o to save and press [Enter] to save, then Control+x to [Exit].

and test…

Cron jobs

31, August 2009

Cron tabs can be used to automate jobs on your system by running programs or scripts at prdefined times, dates or days, each user can have their own cron tabs or they can be run as root. To open a crontab, type the following in a [Terminal];

crontab -e

this will open in the vi text editor, but if you prefere the gedit text editor, run the following command;

export VISUAL=gedit

If you stick with vi then use Control+o followed by [Enter] to save your tab, then Control+x to [Exit].

When you run crontab -e, you will get an empty crontab with just the following [or similar] dispalyed;

# m h dom mon dow command

the headings are described below and I usually add these to the top of the file to make things easier to edit. So my crontab looks like this:

# m h dom mon dow command

# mins -> minutes (0-59)

# hours -> hour (0-24)

# DayOfMonth -> day of month (1-31)

# month -> month (1-12)

# DayOfWeek -> day of week (0-6) [Sunday is 0], or

# DayOfWeek -> day of week (mon – sun)

# You can use ‘,’ ‘-’ to give you 1,2,3,5 or 1-5 etc

# The * is used as a wildcard i.e every month

# m h dom mon dow command

# * * * * * /command


each of the 6 command requires a space between them, here are a few examples;

### runs cron 2 mins past every hour ###

2 * * * * /home/martin/bin/

### runs cron every 2 minutes ###

# m h dom mon dow command

*/2 * * * * /home/martin/bin/

#01 * * * * root run-parts /etc/cron.hourly

#The run-parts script is simple enough: it just runs all the executables in the specified directory

### runs cron every fri at 15:30 ###

# m h dom mon dow command

30 15 * * * fri /home/martin/bin/

Scanner Support

27, May 2009

First the bad news, although some scanners are supported in ubuntu/linux many are either not supported at all or only basic scanning is supported, in my case my Visioneer 4800u is not supported at all! As I wanted to move completely over to ubuntu I decided to buy a second hand scanner from eBay. I checked for compatible scanners on the SANE [Scanner Access Now Easy] project page here by checking out the Supported Devices listed my Manufacturer page. I then bid on a Canon CanoScan N650U Flatbed Scanner and got is for £12.31 including postage [result!]

If your scanner is supported then you may need to add the SANE front and back ends to your system as follows: Open the [Synaptic Package Manager] and add the the following packages;

sane, sane-utls, xsane & xsane-common

You can now plug in your scanner and open the [XSane Image Scanner] from the [Applications], [Graphics] menu and if all goes well your scanner name should show in the dialogue title bar and if you press Scan you should be up and running.

Ubuntu Gusty v7.10 and possibly older versions may need to have scanbuttond (yes there is a d at the end) running for the scanner operation to be detected. To add the scanbuttond type the following in a [Terminal];

sudo apt-get install scanbuttoned

To run the program manually type the following after the prompt;


To make this program run at start-up so you don’t have to do this each time you want to scan open [System], [Preferences], [Sessions] click on the [Start-up Programs] Tab then click the [+ Add] button. A new window will appear, add [Scanbutton] in the [Name] field and scanbuttond in the [Command] field [remember the “d” at the end of scanbuttond, then [OK] that and [Close] when you re start the PC scanbuttond will be running.

Some command line scanner options to try, type or copy and paste the following into the [Terminal] after the prompt;

This will produce a scan without using the XScane graphical interface

scanimage -x 210 -y 290 –resolution 400 –mode Color > /home/yourname/output.jpg

change [yourname] for the name of your [Home] folder and this should produce a scan called output.jpg.

These command line options will help identify your scanner for problem solving;

sane-find-scanner -v -v

scanimage -L

cat /proc/bus/usb/devices

redirect their output to a text file to make things easier by adding >> scanner_test.txt to the end of each line. The >> part appends the text to the end of the last so you will not overwrite the output from the last command.

sane-find-scanner -v -v >> scanner_test.txt

or use this script, create the script file using;


open the file with;


then copy and paste the text below into it.

## created by Martin Cooper 27 May, 2009 ##
echo “Scanner test script” >> scanner_test.txt
echo “sane-find-scanner -v -v output” >> scanner_test.txt
echo “*********************************************” >> scanner_test.txt
sane-find-scanner -v -v >> scanner_test.txt
echo “scanimage -L output” >> scanner_test.txt
echo “*********************************************” >> scanner_test.txt
scanimage -L >> scanner_test.txt
echo “cat /proc/bus/usb/devices” >> scanner_test.txt
echo “*********************************************” >> scanner_test.txt
cat /proc/bus/usb/devices >> scanner_test.txt

now save the file and make it executable with;

chmod +x ~/

and now run it by running this command


or double click on the file. The result will now be in the file scanner_test.txt in your home Directory.

Notes: Feisty v 7.04 onwards Gnome Desktop

My First Script

26, May 2009

This is not my first script but I was asked by a friend to start him off in the right direction so after writing this out I thought I should at least post it!

Ubuntu, for some reason unknown to me uses the Dash shell which causes problem with some scripts written in the standard Bash shell. To make things easier from the start it is better to swap over to do this open a Terminal [Applications], [Accessories], [Terminal] and type or copy & paste the following;

echo $SHELL

and press [Enter], you should get a response like this;


which is your current Shell, the [echo] means print the following to the screen. Now lets change it to the Bash shell, type the following in the [Terminal]

sudo rm -f /bin/sh

and press [Enter], you will then be asked to enter your password as the sudo option means you are working as the root [super user] and this requires a password to make it secure. now type the following;

sudo ln -s /bin/bash /bin/sh

the first command removes the symlink [symbolic link, which Windows users will know as a shortcut] which links Dash to the sh command and the second adds a link from the bash shell to the sh command. Now type this again;

echo $SHELL

your should now get;


Now lets set-up a folder in your home directory to store your scripts in and allow the system to locate them by adding the new directory to your path. Create a new folder by typing;

mkdir bin

as the [Terminal] starts up in you [home] directory the bin directory will be created there. you can list the contents of your home by typing;


and [Enter] which will list all the directories [in blue] & files [in black]. Now lets add the bin directory to your path, this is where the system looks for files you ask it to launch. To see your current path, type the following.

echo $PATH

which will give you something like;



and then repeating the command;

echo $PATH

will now give you;


Any executable scripts you place in your bin directory can run by typing their name in a [Terminal] as we will see later. We will now create our first script using the Touch command.

touch ~/bin/

the ~/ is short for the path to your home directory i.e. /home/martin/ and the rest adds the file called in the bin directory. We need to add some commands to the file so open it in gedit by typing;

gedit /home/martin/bin/

Then copy and paste the following into the file, save it and close gedit, the first line is know as the “shebang” and point the system at the shell you are using, the lines starting ## are comments and will not be run.

## created by Martin May 2009 ##
## say hello ##
## we give the variable today a value which represents ##
## day, date & time and prints it later by adding a $ to it ##
today=`date +%a%t%d%t%B%t%Y%t`
## ask your name and read it into a variable called name ##
echo -n “Enter your name: ”
read name
## clear the screen ##
## we now give the variable time the current system time ##
time=`date +%T`
## now lets print it all out to the screen ##
echo “Hello World!”
echo “Welcome ” $name
echo “Today is “$today
echo “and your logon time was : “$time

We can now try and run the script by typing it’s name in the [Terminal];


which will result in;

bash: /home/martin/bin/ Permission denied

This is because the script is not yet executable, so type the following;

chmod +x ~/bin/

and run the script again with;

It should then ask for your name and display the result with a welcome message including the time as follows;

Hello World!

Welcome Martin

Today is Tue 15 May 2009

and your logon time was : 22:33:24

Once you have this basic script running, you can start making changes and playing with the output.