I hope my english will be sufficient to open a discussion...sorry if you find some mistake! I'm trying to write a bash script to launch byzanz-record, a screen recorder under Linux Fedora, for an undetermined time, until it will be stopped by another script. Byzanz-record wants an option, --duration, to specify the duration of recording, but I would that it could be indefinite instead. Trying to give this command:
byzanz-record -v -a -c --display=:0.0 --width=1366 --height=768 --duration=86400 --delay=0 ~/Video/test.flv
to stop it then manually with a kill command, when decided, I obtain a test.flv file with a virtual duration of 24h (86400 seconds), without the possibility to use the timeline slider to scroll in the video, because the video is actually much less than 24 hours, so It's very difficult, and then I want to get a video that shows a real duration. So I'm thinking to use an ambient variable as --duration option. I'm trying it in this way:
#!/bin/bash
pid_byzanz=$(ps -o pid --no-headers -C "byzanz-record")
sec_byzanz=$(ps -p ${pid_byzanz} -o etime= > /tmp/byzanz_elapsed_time && more /tmp/byzanz_elapsed_time | sed -E 's/(.*):(.+):(.+)/\1*3600+\2*60+\3/;s/(.+):(.+)/\1*60+\2/' | bc)
x=$(( ${sec_byzanz} + 3 ))
byzanz-record -v -a -c --display=:0.0 --width=1366 --height=768 --duration=$x --delay=0 /home/Riccardo/Video/test.flv
exit
where I create two ambient variables, ${pid_byzanz} and ${sec_byzanz}, the first of which registers the PID of byzanz-record's process, necessary for the command "ps -p PID -o etime=" which gives me the time duration of launched process, in hh:mm:ss format, which then I translate in seconds with command:
sed -E 's/(.*):(.+):(.+)/\1*3600+\2*60+\3/;s/(.+):(.+)/\1*60+\2/' | bc
which I would register in the ambient variable ${sec_byzanz}, that I think should be increased by an arbitrary number (for example 3) to allow the process to start, otherwise it could end up in the same instant in which it starts, and in this way perhaps I should be able to get an indefinite period for my process (because the --duration option would be the sum of 3 with a number that increase itself, until the next killing generated from another launched script).
This is my idea, but the script doesn't works as expected, since it doesn't sum my ${sec_byzanz} variable with 3, but it creates a video with only 3 seconds as duration. How I can realize my purpose. I'm at the beginning of bash scripting, and I tryed to find a solution on google, until I found this page (How can I add numbers in a bash script) to sum two variables, which I tryed without a goal, so my request directly to you.
I hope in a solution.
Greetings,
Riccardo
Edit 1:
In a terminal, I give the command:
./launch_byzanz-record
where "launch_byzanz-record" is my script with inside:
#!/bin/bash
pid_byzanz=$(ps -o pid --no-headers -C "byzanz-record")
sec_byzanz=$(ps -p ${pid_byzanz} -o etime= > /tmp/byzanz_elapsed_time && more /tmp/byzanz_elapsed_time | sed -E 's/(.*):(.+):(.+)/\1*3600+\2*60+\3/;s/(.+):(.+)/\1*60+\2/' | bc)
x=$(( ${sec_byzanz} + 60 ))
byzanz-record -v -a -c --display=:0.0 --width=1366 --height=768 --duration=$x --delay=0 /home/Riccardo/Video/test.flv
exit
and the output of commad for current processes is:
$ ps ax | grep byzanz-record
4314 pts/1 S+ 0:00 /bin/bash ./launch_byzanz-record
4318 pts/1 Sl+ 0:04 byzanz-record -v -a -c --display=:0.0 --width=1366 --height=768 --duration=60 --delay=0 /home/Riccardo/Video/test.flv
4330 pts/0 S+ 0:00 grep --color=auto byzanz-record
until the end of 60 seconds (I increased the seconds to give me the time to test what happens).
Edit 2:
Probably I can do something like this, as idea, that i must try to convert in bash script:
The base is to choose a large fixed number, such as:
24h = "86400 seconds" = "record time" + "extra time"
I want "record time" as value for my option "--duration". So, I may make some like this, probably:
If my process byzanz-record isn't running, my $x ambient variable is a fixed large number (example 86400 seconds);
If my process byzanz-record starts running, instead, my $x become "record time" = "86400 seconds" - "extra time" = "86400 seconds" - ("86400 seconds" - "record time"), where "record time" is the output of "ps -p ${pid_byzanz} -o etime=" command... Might It works as idea?