0

How to run bash script as longs as video length?

I will set up a cron to start bash script at 7PM, and I want to keep it running for as long as video length. How to do It?

Example: 7PM bash scripts starts movie.avi, that Is 3minutes length. Bash script keeps running for 3minutes then shuts down.

1

You could use wait.

From linux man page:

wait, waitpid, waitid - wait for process to change state

All of these system calls are used to wait for state changes in a child of the calling process, and obtain information about the child whose state has changed. A state change is considered to be: the child termi‐ nated; the child was stopped by a signal; or the child was resumed by a signal. In the case of a terminated child, performing a wait allows the system to release the resources associated with the child; if a wait is not performed, then the terminated child remains in a "zombie" state.

As an example:

#!/bin/bash

/usr/bin/vlc --vlc_args &
wait 
echo "VLC has finished."
poweroff # you said: "then shuts down" 
0

If you want your bash script to play the video and quit when the video ends, you can use the vlc option --play-and-exit like this:

#! /bin/bash
vlc --play-and-exit /path/to/video.mpg

This way vlc will automatically exit when the video stop at the end.

0

Not sure how you're calling the video software from the script, but as long as the software closes after the movie is complete, you could just use wait:

#!/bin/bash

/video/software &
$PID=$!

wait $PID
echo "Movie complete!"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.