not waiting...why?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting not waiting...why?
# 1  
Old 11-14-2008
not waiting...why?

My shell script is not waiting. I right click on a file and say convert it to whatever and it runs this script. It converts it using Compressor but I want it to wait until it is 100% done before moving on and it is not waiting. I have tried to put it in the background and using "wait". I have tried to check for the file existence of the new file (new file shows up prematurely...before the entire encoding has been done so this is out). Anyone else recommend anything else?

HTML Code:
#! /bin/sh
exec > /tmp/keith 2>&1
set -x
date
open /Applications/Utilities/Batch\ Monitor.app 

/Applications/Compressor.app/Contents/MacOS/./Compressor \
	-clustername 'This Computer' \
	-batchname 'FLV-480X360' \
	-priority low -jobpath "$1" \
	-settingpath '/Users/keith/Library/Application Support/Compressor/FLV - 480 X 360.setting' \
	-destinationpath "$2"

if [ $? != 0 ]
then
	echo "failure from Compressor...$?" | mail -s "$3 failed" myemail@email.com
	echo "Compressor failed"
	open /tmp/keith
	exit 1
fi 

if [ -s $2 ]
  then
   flvtool2 -U "$2"
open -a /Applications/QuickTime\ Player.app "$2"

open /System/Library/CoreServices/Finder.app "$4"
fi

echo "FLVTOOL2 returned $?"

if [ $? != 0 ]
then
	echo "failure from FLVTOOL2...$?" | mail -s "$3 failed" myemail@email.com
	echo "FLVTOOL failed"
	open /tmp/keith
	exit 1
fi
# 2  
Old 11-14-2008
Have you tried changing the tests for 0 from != to -ne ?
So instead of if [ $? != 0 ] use if [ $? -ne 0 ]

S.
# 3  
Old 11-14-2008
I have simplified it to just open the file after conversion. I think the problem is the script thinks it is done when the file is created like 30 seconds into encoding or so. However, the file is not 100% complete. In the script below the QT player never opens.

I'm not sure what to do next...any suggestions?

HTML Code:
#! /bin/sh
exec > /tmp/keith 2>&1
set -x
date

/Applications/Compressor.app/Contents/MacOS/./Compressor \
	-clustername 'This Computer' \
	-batchname 'FLV-480X360' \
	-priority low -jobpath "$1" \
	-settingpath '/Users/keith/Library/Application Support/Compressor/FLV - 480 X 360.setting' \
	-destinationpath "$2" &&
wait

if [ $? -ne 0 ]
then
	  open -a /Applications/QuickTime\ Player.app "$2"
fi

This is my log file:
HTML Code:
+ date
Fri Nov 14 12:29:20 EST 2008
+ /Applications/Compressor.app/Contents/MacOS/./Compressor -clustername 'This Computer' -batchname FLV-480X360 -priority low -jobpath /Users/keith/Desktop/test/file.mov -settingpath '/Users/keith/Library/Application Support/Compressor/FLV - 480 X 360.setting' -destinationpath /Users/keith/Desktop/test/file.flv
2008-11-14 12:29:21.971 Compressor[456:10b] owner is: keith
2008-11-14 12:29:21.994 Compressor[456:10b] <jobID E4477B97-0E68-4625-97EE-125F1D27843A /> <batchID 67A9FB90-2187-4442-A9CA-CB964F963BDD />
+ wait
+ '[' 0 -ne 0 ']'
# 4  
Old 11-14-2008
In your script I notice a double && which should be just ambersand. Further, the test should now read [ $? -eq 0 ] instead of [ $? -ne 0 ] and then it will launch the player I think.

If then still Quicktime launches before the conversion is finished I suggest you have a look at /Applications/Compressor.app/Contents/MacOS/./Compressor, which I suspect is a script in itself that may be launching the actual program in the background without waiting for it to finish. Perhaps you could then use wait loop until the creation of the file is finished (wait for a feature of the new file to change, e.g. test for non-zero length, maybe?)

S.
# 5  
Old 11-14-2008
Ya I put only one & and changed it to [ $? -eq 0 ] and QT pops up once the file is created but not when the file is complete. If you check the info of the file when converting it keeps adding to the file size. So I'm not sure how I would know when it is 100% done. I tried to open the Compressor script but of course it is all mumbo jumbo.

Any suggestions?
# 6  
Old 11-14-2008
Perhaps you could keep checking the file every few seconds to see if the files size stopped changing, e. g. like so:

Code:
NEW=$(ls -s "$2")
while [[ "$NEW" != "$OLD" ]]; do
  sleep 5
  OLD=$NEW
  NEW=$(ls -s "$2")
done

S.

Last edited by Scrutinizer; 11-14-2008 at 06:15 PM..
# 7  
Old 11-14-2008
I think it works now but I'm totally confused as to why it is behaving this way. The script below works...or at least once the file has encoded completely the QT movie opens...about 15 seconds or so later. That is weird to me. Another weird thing is before the flv would show up even though the file was not 100%. Now the file does not show up until 15 seconds or so after the file has completed.

Note: Scrutinizer you initially recommended 5 seconds to sleep. I changed it to 15 because QT was opening early like before. When I check the log file it said the two values did equal each other. I assume maybe the file took a 5 seconds break or something so I increased it to 15 and it fixed it.

HTML Code:
#! /bin/sh
exec > /tmp/keith 2>&1
set -x
date

/Applications/Compressor.app/Contents/MacOS/./Compressor \
	-clustername 'This Computer' \
	-batchname 'FLV-480X360' \
	-priority low -jobpath "$1" \
	-settingpath '/Users/keith/Library/Application Support/Compressor/FLV - 480 X 360.setting' \
	-destinationpath "$2" &
wait

if [ $? -eq 0 ]
then

NEW=$(ls -s "$2")
while [ "$NEW" != "$OLD" ]; do
  sleep 15
  OLD=$NEW
  NEW=$(ls -s "$2")
done
	  
if [ "$NEW" == "$OLD" ]
then
open -a /Applications/QuickTime\ Player.app "$2"
fi

fi
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Debian

Waiting for localhost.

I am getting the message - waiting for localhost. Here are some diagnostic steps I have tried .... root@meow:/home/ethan# cat /var/www/cgi-bin/httpd.conf ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/jkj ServerName 127.0.0.1:80 Listen xx.xx.xx.xx:80 Listen 127.0.0.1:80 ... (1 Reply)
Discussion started by: Meow613
1 Replies

2. HP-UX

Some I/O requests to this LV are waiting

Hi All I have a blade BL860c running on a C7000 chassis, in which is connected to a NetApp, so lately I am having I/O issues, and dmesg as well as syslog.log is reporting the following: /dev/vg01/lvol2 file system file data error in dev/block 0/55892768 Page I/O error occurred while paging... (2 Replies)
Discussion started by: fretagi
2 Replies

3. UNIX for Dummies Questions & Answers

Waiting for a file

I am such a newbie. I am from a mainframe background, so this stuff is new for me to interpret. I dont know if I need a sleep or wait. I need a loop to wait for a filea or fileb to be created before I execute further script. The driver unix script is on the solaris. The files I'm looking for... (1 Reply)
Discussion started by: Lillyt
1 Replies

4. Shell Programming and Scripting

not waiting

I have a script that runs Compressor and converts the file then I want it to inject the file with Flvtool2. My script works fine but the flvtool2 is starting too early. I have tried to put it in the background by putting a "&" sign at the end and then put a "wait" on a new line. Anyone have any... (2 Replies)
Discussion started by: mainegate
2 Replies

5. Shell Programming and Scripting

waiting

I have a text file which contain all the parameters need for scheduled jobs, then this "control" script would be called everynight at certain time while read line do $myScript.sh $line & pid=$! i=`expr $i + 1` done < $list then I need to wait until all... (1 Reply)
Discussion started by: mpang_
1 Replies

6. UNIX for Dummies Questions & Answers

Waiting between commands

Hello, Taking my scripting one step farther, I want to run a number of commands one after the other, but the system should wait between commands. How do I do this? Do I use the /wait command, or is it a function wait()? rsync command /wait tar command /wait move to a new folder /wait... (1 Reply)
Discussion started by: patwa
1 Replies

7. UNIX for Advanced & Expert Users

browser waiting

hi all i am opning a browser like www.example.com i would like to open this browser slowly (wait mode) how can i do this. is there any option like wait for some time that to 5sec.,10 sec. like (1 Reply)
Discussion started by: munna_dude
1 Replies

8. Shell Programming and Scripting

Looping and waiting

Hi Is it possible to have a script run in a loop (waiting for a change of state in the network interface), and if the loop continues for five minutes, to have it email the admin, and carry on in the loop? Here is my loop: #!/bin/bash STATE=`echo "show... (3 Replies)
Discussion started by: mikie
3 Replies

9. Shell Programming and Scripting

Waiting on a group

In the below artificially simplified script, I want to wait till after a, b, and c have been printed, before printing "finished." If you just want to wait on a single background process, you can use $! (pid of the last background process). But this doesn't work if there's more than one... (1 Reply)
Discussion started by: tphyahoo
1 Replies

10. Linux

waiting process

how to know the information of the waiting process how to calculate the time of the process that it has taken to execute i want to make a program that Should be able to keep a log of the processes expired(The log should contain the starting time, expiry time, time slices used, total execution... (2 Replies)
Discussion started by: shukla_chanchal
2 Replies
Login or Register to Ask a Question