Executing a sequence of commands as a single background process


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Executing a sequence of commands as a single background process
# 1  
Old 10-02-2009
Executing a sequence of commands as a single background process

I'm writing a PHP script which will take a given media file and convert it into a flash (flv) file. In addition to this, once the flv file has been generated I create two thumbnails (of different sizes) from the newly generated flv file.

In order to do this I'm calling ffmpeg from the command line with the following 3 calls:

1. Generate the flv from the mpg
Code:
/usr/bin/ffmpeg -i /home/.../input.mpg -ar 22050 -ab 64k -b 400k -r 25 -f flv -y -s 304x240 -padright 8 -padleft 8 /home/.../output.flv >> /home/.../log.txt 2>&1

2. Generate the 'lrg' thumbnail
Code:
/usr/bin/ffmpeg -i /home/.../output.flv -f mjpeg -y -s 320x240 -vframes 1 -ss 8 -qscale 6 -an /home/.../thumb-lrg.jpg >> /home/.../log.txt 2>&1

3. Generate the 'sml' thumbnail
Code:
/usr/bin/ffmpeg -i /home/.../output.flv -f mjpeg -y -s 100x74 -vframes 1 -ss 8 -qscale 6 -an /home/.../thumb-sml.jpg >> /home/.../log.txt 2>&1

Note that the 2nd and 3rd thumbnail generation commands rely on the output flv file generated by the 1st command.

These commands are all working fine if I execute them individually. However I would like to combine them into a single command which can be executed in the background. The reason for this is to allow me to pass this to the server via the php exec() function.

Searching around I believe I can do this by adding semi-colons between the commands and adding a ampersand to the end of the final command.

I've tried running this directly through the terminal using the following command (this is fairly lengthly...)

Code:
/usr/bin/ffmpeg -i /home/atw90m/public_html/ffmpeg_test/DELTA.MPG -ar 22050 -ab 64k -b 400k -r 25 -f flv -y -s 304x240 -padright 8 -padleft 8 /home/atw90m/public_html/ffmpeg_test/20091002144718.flv >> /home/atw90m/public_html/ffmpeg_test/20091002144718-ffmpeg.txt 2>&1;

/usr/bin/ffmpeg -i /home/atw90m/public_html/ffmpeg_test/20091002144718.flv -f mjpeg -y -s 320x240 -vframes 1 -ss 8 -qscale 6 -an /home/atw90m/public_html/ffmpeg_test/20091002144718-lrg.jpg >> /home/atw90m/public_html/ffmpeg_test/20091002144718-ffmpeg.txt 2>&1;

/usr/bin/ffmpeg -i /home/atw90m/public_html/ffmpeg_test/20091002144718.flv -f mjpeg -y -s 100x74 -vframes 1 -ss 8 -qscale 6 -an /home/atw90m/public_html/ffmpeg_test/20091002144718-sml.jpg >> /home/atw90m/public_html/ffmpeg_test/20091002144718-ffmpeg.txt 2>&1 &

When I execute this however, only the first two commands appear get fully executed.
Reading the log file, the final command appears to stop mid-way through.

Can you see what I'm doing wrong here?


thanks for your help

Last edited by phatphug; 10-02-2009 at 11:27 AM.. Reason: Clearer formatting
# 2  
Old 10-02-2009
Hi.

(prog1; prog2; prog3) &

should do the trick. In case not, could you please reformat your post to use code tags? Thanks.
# 3  
Old 10-02-2009
Thanks for your reply scottn.

When I try that the first command fails to execute properly.

In normal operation the log would look something like:
Code:
Stream mapping:
  Stream #0.0 -> #0.0
Press [q] to stop encoding
frame=  210 fps=  0 q=3.5 Lsize=     563kB time=8.40 bitrate= 549.4kbits/s    
video:560kB audio:0kB global headers:0kB muxing overhead 0.618644%

With the brackets the log file ends after the "Press [q] ..." message

Code:
Stream mapping:
  Stream #0.0 -> #0.0
Press [q] to stop encoding

# 4  
Old 10-02-2009
Hi.

I'm not sure why that might happen.

Either try:
Code:
prog1 && prog2 && prog3 &

Or, failing that, put the three commands into a script
Code:
prog1
prog2
prog3

And run the script with &
# 5  
Old 10-02-2009
The &&'s had the same problem as the brackets.
It did work when running via a script though.

Strangely, when calling exec() in php with brackets around the 3 commands they do work. I'm not sure why the same doesn't work in terminal, but since I only need a working solution in php, this will do me.

Thanks for your help scottn.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Make background process interact with fg process

Hi, I have written a menu driven shell script in which as per the choice, I run the another script on background. For eg: 1. get info 2)process info 3)modify info All the operations have different scripts which i schedule in background using &. However I wish to display the error... (0 Replies)
Discussion started by: ashima jain
0 Replies

2. Shell Programming and Scripting

Executing a background script using ssh keys

Greetings, i've been working with a user-friendly menu on ksh to allow users execute scripts located on a remote server, so they wont have to login and manually launch those scripts every single time. This is a HP-UX box and currently on a /usr/bin/ksh shell. I've setup ssh keys on both... (1 Reply)
Discussion started by: nbriozzo
1 Replies

3. Shell Programming and Scripting

How to put FTP process as a background process/job in perl?

Hi, I am using net::ftp for transferring files now i am trying in the same Linux server as a result ftp is very fast but if the server is other location (remote) then the file transferred will be time consuming. So i want try putting FTP part as a background process. I am unaware how to do... (5 Replies)
Discussion started by: vanitham
5 Replies

4. Shell Programming and Scripting

A puzzle with a printing function executing in background

Somebody on a thread in the (french) Mandriva Forum recently suggested a script, designed to provide a tool to display kind of "temporisation widgets" on the console (to be ultimately pasted in other more complex scripts). One version of this script was something like the following, which seems... (6 Replies)
Discussion started by: klease
6 Replies

5. AIX

Command executing to be in the background !

Guys I'm working to make in AIX script and I have some commands need to be excited by that script Like the below commands ... startsrc -s sshd I want that executing to be in the background of the system I do not like to see the out put of that (3 Replies)
Discussion started by: Mr.AIX
3 Replies

6. Shell Programming and Scripting

Multiples commands between pipes and a single process

Hi I have this script: #!/bin/ksh cmd1 | cmd 2 |cmd 3| cmd4 which it creates 4 process.... Is possible to create a single process PID1 which include all commands? Thanks Israel (2 Replies)
Discussion started by: iga3725
2 Replies

7. Shell Programming and Scripting

Sequence in one single line

My file looks like this (60 characters per line): But I need something like this (the entire sequence in one line): The sequences are of different lengths. Any help will be very much appreciated! (21 Replies)
Discussion started by: Xterra
21 Replies

8. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

9. Shell Programming and Scripting

capture the process id when starting a background process

Hello all, How do I start a background process and save the process id to a file on my system. For example %wait 5 & will execute and print the process id. I can't figure out how to get it to a file. I've tried: > filename 0>filename 1>filename. Any assistance is most appreciated. Thanks, Jim... (10 Replies)
Discussion started by: jleavitt
10 Replies
Login or Register to Ask a Question