You are not logged in.
Im writing a script that will mount my cd-drive, execute a windows program, detect when the program closes and if the process no longer exists it will unmount the drive. The only problems that I ran into was I dont know how to make the script wait until the program is finished running to continue running through the script. Basically what I'm looking for is a linux equivalent to the "start /wait" windows command. I also just realized that I cant use "ps -C xbc" as I originally intended since xbc is the name of the script and the conditional statement will never work so I also need to find a way for it to look for the program, I tried ps -C "Xbox Backup Creator.exe" but that didnt output anything.
Heres what I have so far
#!/bin/bash
sudo mount /dev/hdc /media/xbox.ripper
wine "/media/mybook/XBOX Stuff/Xbox 360/Game Ripping/Xbox Backup Creator v2.9.0.306/Xbox Backup Creator.exe"
ps -C [something that will work] > exists #if the xbox backup creator process exists it creates a file with a size larger then 0 bytes
#line to pause the script until xbox backup creator closes goes here
if [[ ! -s exists ]] #the statement is true if the file "exists" is NOT larger then 0 bytes
then
sudo umount /dev/hdc
fi
rm exists
Last edited by brando56894 (2009-12-07 17:37:04)
Offline
man pgrep
Offline
Does `pgrep -lf Xbox` return anything? If so then `XBOXPID=$(pgrep Xbox)` will either be nil or the pid of the process, which you can test with `[ -z $XBOXPID ]`
If that doesn't do anything, then `ps aux` and see if you can find the actual process name, and work from there with the above info. I'm assuming that "Xbox" will be somewhere in the process string, adjust case as necessary.
HTH
Edit: F*** beaten.
Last edited by Kitty (2009-12-07 07:04:27)
/etc/rc.d/ is where daemons reside. Beware.
Offline
yea that worked thanks! I didnt even know the pgrep command existed, I had to remove the backquotes for the command to work though.
Offline
Backticks actually .
Setting Up a Scripting Environment | Proud donor to wikipedia - link
Offline
quotes,ticks, right facing downward pointy things, whatever you want to call them I had to remove them
The script works perfectly, thanks for the help.
Last edited by brando56894 (2009-12-07 17:36:47)
Offline
YW, and yeah, was being lazy with the backticks, I didn't want to mess with the <code> formatting.
/etc/rc.d/ is where daemons reside. Beware.
Offline
pgrep also returns true/false so you can do pgrep Xbox >/dev/null|| sudo umount ... instead of storing it in a variable and reading it with [ -z ... ]
Offline
but how would pgrep xbox > /dev/null || sudo umount be conditional? im assuming the double pipe is the boolean operator 'or', correct?
YW, and yeah, was being lazy with the backticks, I didn't want to mess with the <code> formatting.
ah ok i was assuming it was part of the command string since its used sometimes to execute the stuff thats inside them.
Offline
Basically what I'm looking for is a linux equivalent to the "start /wait" windows command
Feel free to use the above solution, but wine has a start command built in. Try
wine start /W ...
, or
wine start /?
to find out how to use it.
"You can watch for your administrator to install the latest kernel with watch uname -r" - From the watch man page
Offline
this is what i ended up using and it works perfectly
#!/bin/bash
sudo mount /dev/hdc /media/xbox.ripper
wine "/media/mybook/XBOX Stuff/Xbox 360/Game Ripping/Xbox Backup Creator v2.9.0.306/Xbox Backup Creator.exe"
xboxpid=$(pgrep Xbox)
if [[ -z $xboxpid ]]
then
sudo umount /dev/hdc
fi
Offline