Modules
· Home
· Content
· Encyclopedia
· FAQ
· HotLinks
· Private Messages
· Reviews
· Search
· Statistics
· Stories Archive
· Submit News
· Surveys
· Web Links
· Your Account
  Who's Online
There are currently, 11 guest(s) and 0 member(s) that are online.

You are Anonymous user. You can register for free by clicking here
  Promotion



  HotLinks
· Silicon Tao
· Lethbridge LUG
· Radados
· MySQL Group
· Chinook CCC
· OS Guild
· Edmonton LUG
· Calgary LUG
· Red Deer OSS
· CLUE
· OpenSource News
· Leth. College
· University of L
· CanOpener
· LinuxForums
· KDE-Look
· Art Gnome
· TransGaming
· Slashdot
· LinuxNews
· Freshmeat
· LinuxBeta
· Hack-a-day
· Google
 Automatic USB icon for xtdesktop

Tips and tricksLinuxGuru writes "The real point of this is the power of bash and how to use it to restart a program. I was in need of a way to restart a program for any user on any desktop so this is what I did.

So Bob is running some program on his desktop. The program has locked up and Bob asks root restart it. Sure root can kill the program but how can root start it up again and put it on Bob's desktop as if Bob ran the program? That was the problem I had.

I am working with a Linus Distro of my own flavor built from Debian and Knoppix. I am using icewm for the desktop and Xtdesk to give it icons. I wanted my USB memory stick have an icon that shows up when the USB drive is plugged in and remove the icon when it is un-plugged.

This simple bash script is an example of how I am able to use hotplug to restart the xtdesk application on any users desktop.

My first problem is that the hotplug scripts are running as the root user. The hotplug scripts are run when there is an event with the system. I don't know much about hotplug but I think you can do almost anything you want with a script when an event happens.

For this project I used icewm but you can use any desktop you like. Xfce, blackbox, windowmaker are all great desktops in need of icons.

Xtdesk uses a local directory in the users HOME to contain the configs for xtdesk and each icon. xtdesk only reads the icon config files when it first starts up. Any changes you make to the config files will not show until the next time it is started. For my configuration of xtdesk I am using a common directory /etc/X11/xtdesktop and every user has a symbolic link in their home that points to that. In that directory I created a new icon for my USB drive called usbmedia.lnk.hide. xtdesk will read all config files that end in lnk so I added the hide suffix to hide this config file from xtdesk. This is the normal state of the USB memory stick, un-plugged.

The first script I had to edit my hotplug script. Your system will most likely have different locations and names for your scripts but these are mine

File name: /etc/hotplug/usb/usb-storage # ---- BEGIN #!/bin/sh . /etc/hotplug/hotplug.functions if [ ! -L /var/run/usb/%proc%bus%usb%* ]; then mesg Try to Mount if [ ! -d /mnt/usbstorage ]; then mkdir /mnt/usbstorage fi # It takes a second for the module to finish loading sleep 1 NOT_MOUNTED=1 mount -t ext2 -o user,exec,sync /dev/sda /mnt/usbstorage > /tmp/hotplug.log 2>&1 NOT_MOUNTED=$? if [ $NOT_MOUNTED -ne 0 ]; then mount -t ext2 -o user,exec,sync /dev/sda1 /mnt/usbstorage > /tmp/hotplug.log 2>&1 NOT_MOUNTED=$? fi if [ $NOT_MOUNTED -ne 0 ]; then mount -t vfat -o user,exec /dev/sda /mnt/usbstorage > /tmp/hotplug.log 2>&1 NOT_MOUNTED=$? fi if [ $NOT_MOUNTED -ne 0 ]; then mount -t vfat -o user,exec /dev/sda1 /mnt/usbstorage > /tmp/hotplug.log 2>&1 NOT_MOUNTED=$? fi if [ $NOT_MOUNTED -eq 0 ]; then cp /etc/X11/xtdesktop/usbmedia.lnk.hide /etc/X11/xtdesktop/usbmedia.lnk xtdesk.restart ln -s /etc/hotplug/usb/usb-storage.off $REMOVER mesg make REMOVER in $REMOVER fi fi # ---- END If you read this script you will see that it tests for vfat and ext2 formated UBS memory sticks that are /dev/sda or /dev/sda1 devices and then mounts the device.

If the device was mounted then the usbmedia.lnk.hide config file is copied to usbmedia.lnk and the xtdesk.restart script is called.

And now for the cool part.

File name: /usr/bin/xtdesk.restart # ---- BEGIN #!/bin/bash RESTART_USER_ID=`id -u` PRG_CMD="false" ALL_XT_PIDS=`ps -C xtdesk|grep xtdesk|gawk '{print $1}'` for EACH_PID in $ALL_XT_PIDS; do ENVIRON_VALUES=`cat /proc/$EACH_PID/environ | tr "

Note: These scripts are licesnsed under the GNU GPL."



 
  Login
Nickname

Password

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.
  Related Links
· More about Tips and tricks
· News by Admin


Most read story about Tips and tricks:
Automatic USB icon for xtdesktop

  Article Rating
Average Score: 4
Votes: 1


Please take a second and vote for this article:

Excellent
Very Good
Good
Regular
Bad

  Options

 Printer Friendly Printer Friendly


Re: Automatic USB icon for xtdesktop (Score: 1)
by LinuxGuru on Wednesday, August 24 @ 00:21:46 MDT
(User Info | Send a Message)
So I tried this script on Mandrake and it did not work. Then I tried it on systems with newer kernels and they also did not work.

I made some fixes to the script and tested it on Debian and Mandrake systems with many version of 2.6 kernel and it is working again.

You can get a new version of the script here








All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest © 2002 by me
You can syndicate our news using the file backend.php or ultramode.txt
PHP-Nuke Copyright © 2005 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.21 Seconds