You are not logged in.
I'm not much of a programmer and trying to write two silly little bash functions, both have problems.
1) function to mount a pen drive as a normal user, run xfe, then unmount the pen drive:
function pen(){
echo "Insert Pen Drive into USB port now!"
sleep 4
sudo mount -t vfat /dev/sdb1 /media/pen
xfe /media/pen
umount /media/pen
}
Problem is the sudo thing does not work. It does not stop to ask for a password so fails in mounting. Ideas?
2) function to start dropbox daemon, load an OO spreadsheet, work on the spreadsheet and then when OO closes kill the dropbox daemon. However, below does not work as expected, last line gets executed before OO shuts down. Why?
facah(){
dropboxd &
cd ~/Dropbox/facah
sleep 6 && oocalc facah_db.ods
kill `pidof dropbox`
}
Philosophy is looking for a black cat in a dark room. Metaphysics is looking for a black cat in a dark room that isn't there. Religion is looking for a black cat in a dark room that isn't there and shouting "I found it!". Science is looking for a black cat in a dark room with a flashlight.
Offline
1) function to mount a pen drive as a normal user, run xfe, then unmount the pen drive:
function pen(){ echo "Insert Pen Drive into USB port now!" sleep 4 sudo mount -t vfat /dev/sdb1 /media/pen xfe /media/pen umount /media/pen }
Problem is the sudo thing does not work. It does not stop to ask for a password so fails in mounting. Ideas?
Change the owner of the file to root, use chmod to make it executable by others and set the SUID. Make use the file is not writable by anyone but the owner (root). When a normal user executes the file, it will run with root privileges. This might not do everything you want. It might run xfe as root. I'm not sure. Never-the-less, you will need root privileges for the dismount.
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
2) function to start dropbox daemon, load an OO spreadsheet, work on the spreadsheet and then when OO closes kill the dropbox daemon. However, below does not work as expected, last line gets executed before OO shuts down. Why?
facah(){ dropboxd & cd ~/Dropbox/facah sleep 6 && oocalc facah_db.ods kill `pidof dropbox` }
The && says "Execute command 1. If, and only if it returns 0 then execute command 2.
Your code is changing directories, waiting 6 seconds, then launches oocalc, which seems to always return 0 after the file opens. Note that oocalc returns 0 after the file opens, but the GUI and the spreadsheet remain open and detaches from the shell (killing the shell does not kill OOcalc)
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
Maybe it should be like this
sudo mount -t vfat /dev/sdb1 /media/pen && xfe /media/pen && umount /media/pen
Run xfe if sudo mount return 0 and umount if xfe return 0
But, it's just my thought...
Ask, and it shall be given you.
Seek, and ye shall find.
Knock, and it shall be opened unto you.
Offline
Change the owner of the file to root, use chmod to make it executable by others and set the SUID. Make use the file is not writable by anyone but the owner (root). When a normal user executes the file, it will run with root privileges. This might not do everything you want. It might run xfe as root. I'm not sure. Never-the-less, you will need root privileges for the dismount.
The kernel ignores the SUID bit on files starting with '#!'.
EDIT: You could use pmount to mount and unmount the drive as a normal user without using sudo.
Last edited by ber_t (2010-06-23 05:54:53)
Offline
Use pmount instead of mount.
Offline
Note that oocalc returns 0 after the file opens, but the GUI and the spreadsheet remain open and detaches from the shell (killing the shell does not kill OOcalc)
You're absolutely right. Thanks for pointing that out. What I think I need to do is have an if test before the kill statement to check whether OO has yet been shut down, or if the spreadsheet file has been changed and then stop the dropbox daemon...
Philosophy is looking for a black cat in a dark room. Metaphysics is looking for a black cat in a dark room that isn't there. Religion is looking for a black cat in a dark room that isn't there and shouting "I found it!". Science is looking for a black cat in a dark room with a flashlight.
Offline
The kernel ignores the SUID bit on files starting with '#!'.
I checked, and you are correct. How did I miss that ? I am sure I have done this in the past. It must have been a binary. I know it worked on a Solaris system I used.
I learn something new every day.
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
Use pmount instead of mount.
That worked. Thanks!
Philosophy is looking for a black cat in a dark room. Metaphysics is looking for a black cat in a dark room that isn't there. Religion is looking for a black cat in a dark room that isn't there and shouting "I found it!". Science is looking for a black cat in a dark room with a flashlight.
Offline