How to cleanly end a process started by at?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to cleanly end a process started by at?

Bo Berglund
I am using my Ubuntu 18.04 server (no gui installed) to manage svn
server and a video website.

The videos I want to watch are part of a live stream sent during night
in my time zone, when I am sleeping.

I have created a script, which packages a call to youtube-dl to
download the stream.

But youtube-dl does not have a timeout argument so for live streams it
runs for exactly 6 hours before ending.
So I have created four at jobs in order to get each 6 hour section
every day.

But this means I have to wait until the download finishes before I can
get the video and view it.
Until it is done the video file remains a name.mp4.part file...

What I would rather do is to somehow set the youtube-dl call to only
run for say 60 minutes rather than 6 hours, then I could record every
video separately and get at them as soon as they finish.

When I run youtube-dl interactively and it is busy downloading (at
that time it is actually ffmpeg running) I can use the keyboard Ctrl-C
to stop the process and this makes the download stop cleanly leaving a
valid mp4 file. So it cleans up the file then exits.

I have tried using the timeout function in Linux, but that seems to
force kill the process including child processes all the way down to
ffmpeg. So it leaves the file.mp4.part file rather than cleaning up...

Is there any way to simulate whatever happens when I hit Ctrl-C on the
keyboard when my script is running interactively in a terminal
session?

Or else, how could I make youtube-dl stop before the 6h built-in
timeout?


--
Bo Berglund
Developer in Sweden


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: How to cleanly end a process started by at?

Colin Watson
On Tue, Dec 08, 2020 at 12:12:30PM +0100, Bo Berglund wrote:

> When I run youtube-dl interactively and it is busy downloading (at
> that time it is actually ffmpeg running) I can use the keyboard Ctrl-C
> to stop the process and this makes the download stop cleanly leaving a
> valid mp4 file. So it cleans up the file then exits.
>
> I have tried using the timeout function in Linux, but that seems to
> force kill the process including child processes all the way down to
> ffmpeg. So it leaves the file.mp4.part file rather than cleaning up...
>
> Is there any way to simulate whatever happens when I hit Ctrl-C on the
> keyboard when my script is running interactively in a terminal
> session?

Ctrl-C sends the SIGINT signal, so "timeout --signal=INT 1h ..." should
do what you want.

--
Colin Watson (he/him)                              [[hidden email]]

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|

Re: How to cleanly end a process started by at?

Bo Berglund
On Tue, 8 Dec 2020 12:18:30 +0000, Colin Watson <[hidden email]>
wrote:

>> Is there any way to simulate whatever happens when I hit Ctrl-C on the
>> keyboard when my script is running interactively in a terminal
>> session?
>
>Ctrl-C sends the SIGINT signal, so "timeout --signal=INT 1h ..." should
>do what you want.
>

Thanks for your response!

It did the trick, now when the task ends the video is properly closed!
I used:
timeout --signal=2 4m getvideo test.mp4 <URL> 94

where getvideo is my script simplifying the use of youtube-dl.

The video was recorded and closed and the resulting length was 4:05
min so it is probably within what can be expected based on the
streaming protocol (94) (where I think many small parts are sent).

Thanks again!


--
Bo Berglund
Developer in Sweden


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users