LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-28-2004, 03:52 PM   #1
TLV
Member
 
Registered: Jun 2004
Distribution: Ubuntu
Posts: 185

Rep: Reputation: 30
bash-script won't wait for application to finish


I'm not sure if this is the right forum to ask a bash-specific question. Let me know if my question should be moved...

I'm writing a bash-script that will activate my s-video port on my computer and then start a media player (specifically noatun). When I have exited the player, I want to script to continue to finish up some things.

So my script looks something like this:

Code:
#!/bin/bash
atitvout -f t   # To activate the s-video port on my ATI card
noatun
atitvout -t l   # To deactivate the s-video port
The problem is that the noatun application starts and the script continues to execute. I don't want the script to continue the execution until after I have exit noatun. (Using another application instead of noatun, e.g. kompare, "pauses" the script.)

How can I "pause" the script while noatun is running?

/TLV
 
Old 09-28-2004, 04:09 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
It probably creates a new process and exits, so there's not an easy way to stop it. What I can thing about is to make a loop checking if it is in the process table (filtering ps result) and going out when it's not. Not a perfect solution but should work.
 
Old 09-28-2004, 04:27 PM   #3
TLV
Member
 
Registered: Jun 2004
Distribution: Ubuntu
Posts: 185

Original Poster
Rep: Reputation: 30
I was afraid that something like that would be needed. My hope was that there was some bash-scripting magic function/tool that I wasn't aware of that would help me... Oh well, suddenly it became more programming than I really wanted...

Thanks anyway,
/TLV
 
Old 09-28-2004, 04:33 PM   #4
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
There are two commands you can try. The bash builtin 'wait' and 'sleep'. The wait command I don't fully understand, so I can't tell you how to use it. The sleep command is followed by a time increment: s for seconds; m for minutes; h for hours; and d for days. If you know how long noatun takes to run to completion, you can follow the noatun command with the sleep command.
Suppose noatun takes 10 seconds to run. The sleep command 'sleep 10s' will pause script execution for 10 seconds before continuing.
The wait command can be stated in such a way that the script will wait until noatun returns exit status before continuing.
 
Old 09-28-2004, 04:56 PM   #5
TLV
Member
 
Registered: Jun 2004
Distribution: Ubuntu
Posts: 185

Original Poster
Rep: Reputation: 30
The prob is that I don't know for how long noatun will run as I intend to watch movies on my TV using the computer as the player...

Quote:
If it ain't broke, TWEAK IT !
Ha, ha, and I thought that I had come up with the engineer's motto that I've been telling people for a couple of years now: "If it ain't broke, try to improve it."

/TLV
 
Old 09-28-2004, 10:16 PM   #6
UsualTuxpect
Member
 
Registered: Aug 2004
Location: New York
Distribution: --------- Gentoo-2004.2 [2.6.8] Redhat-9 [2.6.6]
Posts: 545

Rep: Reputation: 31
Hi TLV,


i wrote this small script to solve ur problem give it a try and tell me..

#! /bin/bash

atitvout -f t # To activate the s-video port on ur ATI card

noatun # Running noatun
#kcalc # dont bother about this its for testing


#********important ***************
#check where ur "pidof" is installed by doing ---> #whereis pidof
#in my case it is in /sbin/pidof so im putting it in my next line...
#*********************************


t=`/sbin/pidof noatun` # checking pid to see if noatun is running

#t=`/sbin/pidof kcalc` #dont bother about this its for testing

while [ -n "$t" ] # while noatun is running
do
echo 'UsualTuxpect' >/dev/null #simply outputting my name to /dev/null
done


if [ -z "$t" ] # If noatun process not running , 'pidof' returns null.
then
echo " "
echo "Process noatun not running."
echo " "
echo "About to deactivate s-video port "

atitvout -t l # deactivating the s-video port

fi # end of if condition

exit 0 # exiting without error




i have tried this script with kcalc and xterm and it seems to be doin the job as i have not
installed noatun on my system...


Post back as to how it went...........

DAMN!!!! I'm So excited just one away from 100

Last edited by UsualTuxpect; 09-28-2004 at 10:37 PM.
 
Old 09-28-2004, 11:58 PM   #7
dustu76
Member
 
Registered: Sep 2004
Distribution: OpenSuSe
Posts: 153

Rep: Reputation: 30
Try doing:

#!/bin/bash
atitvout -f t # To activate the s-video port on my ATI card
noatun &
wait $!
atitvout -t l # To deactivate the s-video port

HTH.
 
Old 09-29-2004, 12:02 AM   #8
dustu76
Member
 
Registered: Sep 2004
Distribution: OpenSuSe
Posts: 153

Rep: Reputation: 30
Btw, just a query for UsualTexpect:

<snip>

t=`/sbin/pidof noatun` # checking pid to see if noatun is running

#t=`/sbin/pidof kcalc` #dont bother about this its for testing

while [ -n "$t" ] # while noatun is running
do
echo 'UsualTuxpect' >/dev/null #simply outputting my name to /dev/null
done

</snip>

In case noatun is found to be running, how do you expect to exit the loop ? I guess you want to do like:

while [ -n "$t" ] # while noatun is running
do
echo 'UsualTuxpect' >/dev/null #simply outputting my name to /dev/null
t=`/sbin/pidof noatun` # checking pid to see if noatun is running
done

HTH.
 
Old 09-29-2004, 12:32 AM   #9
UsualTuxpect
Member
 
Registered: Aug 2004
Location: New York
Distribution: --------- Gentoo-2004.2 [2.6.8] Redhat-9 [2.6.6]
Posts: 545

Rep: Reputation: 31
My bad .. was in a hurry.. its a mistake i made .. darn!!...

completely forgot to put the line [t=`/sbin/pidof noatun`] in the while loop...

thanks dustu76 for the correction...


This is the final program with the line added..


#! /bin/bash

atitvout -f t # To activate the s-video port on ur ATI card

noatun # Running noatun



#********important ***************
#check where ur "pidof" is installed by doing ---> #whereis pidof
#in my case it is in /sbin/pidof so im putting it in my next line...
#*********************************


t=`/sbin/pidof noatun` # checking pid to see if noatun is running



while [ -n "$t" ] # while noatun is running
do
t=`/sbin/pidof noatun` # ********the line i forgot in my last post************
done


if [ -z "$t" ] # If noatun process not running , 'pidof' returns null.
then
echo " "
echo "Process noatun not running."
echo " "
echo "About to deactivate s-video port "

atitvout -t l # deactivating the s-video port

fi # end of if condition

exit 0 # exiting without error
 
1 members found this post helpful.
Old 09-29-2004, 01:35 AM   #10
TLV
Member
 
Registered: Jun 2004
Distribution: Ubuntu
Posts: 185

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by dustu76
Try doing:

#!/bin/bash
atitvout -f t # To activate the s-video port on my ATI card
noatun &
wait $!
atitvout -t l # To deactivate the s-video port

HTH.
Nope, it doesn't work. What does "wait $1" mean?

/TLV
 
Old 09-29-2004, 01:38 AM   #11
TLV
Member
 
Registered: Jun 2004
Distribution: Ubuntu
Posts: 185

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by UsualTuxpect
This is the final program with the line added..
Thanks UsualTuxpert, your code is working great (I just wished there was a way to solve it more elegantly...)

Is that last if-statement really needed? The script wouldn't exit the while-loop unless it was true, right?

Thanks again,
/TLV
 
Old 09-29-2004, 02:11 AM   #12
UsualTuxpect
Member
 
Registered: Aug 2004
Location: New York
Distribution: --------- Gentoo-2004.2 [2.6.8] Redhat-9 [2.6.6]
Posts: 545

Rep: Reputation: 31
U dont need the if loop .... i just wrote it so that one could understand easily..
what i was doin....

go ahead and remove all the stuff u dont want...
 
Old 09-29-2004, 03:10 AM   #13
dustu76
Member
 
Registered: Sep 2004
Distribution: OpenSuSe
Posts: 153

Rep: Reputation: 30
Hi TLV,

Congrats

Its $! (As in exclamation sign) & not $1. $1 would not work.

I'm interested in seeing the results with $! ... could you pls try it out with $!

$! is the process id of the noatun which we put in background using "&" ...


HTH.
 
Old 09-29-2004, 03:34 AM   #14
theonebeyond
Member
 
Registered: Aug 2004
Location: Germany
Distribution: Slackware 10.0
Posts: 258

Rep: Reputation: 30
there is a little programm called "waitfor" ... and it does exactly that...you can wait for an URL, time, and I thinmk a programm too... you should have a look at it!

Greetings, Sascha
 
Old 09-29-2004, 04:00 AM   #15
TLV
Member
 
Registered: Jun 2004
Distribution: Ubuntu
Posts: 185

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by dustu76
Hi TLV,

Congrats

Its $! (As in exclamation sign) & not $1. $1 would not work.

I'm interested in seeing the results with $! ... could you pls try it out with $!

$! is the process id of the noatun which we put in background using "&" ...


HTH.
Yes, I used the "$!", it was just a typo in my post... No, it doesn't work. It get the process id, but it doesn't wait for the process to finish. When I try to run noatun not in the background (w/o '&') I get an error from the wait-command saying that "pid XX is not a child of this shell" (I get the pid from the pidof-command).


/TLV
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I create application launcher using bash script msgclb Programming 2 01-30-2005 06:28 AM
Make script wait for input farmerjoe Linux - General 4 12-28-2004 01:49 AM
while I wait for bash programming jay2901 Programming 4 08-07-2004 07:23 AM
Pppd does not wait for chat script to finish ruchika Programming 1 08-28-2003 11:30 PM
wait in bash shells raypen Linux - Software 1 04-18-2003 02:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration