LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   at -f and shell script (https://www.linuxquestions.org/questions/linux-software-2/at-f-and-shell-script-472093/)

lpn1160 08-08-2006 05:03 PM

at -f and shell script
 
Thanks to all in advance for any help and advice.
I capture videos using this script:

if [ -z "$1" ]; then
echo "Usage: time outputfilenames"
exit 1
fi
mkdir `date +%Y-%d-%m-%H:%M` && cd `date +%Y-%d-%m-%H:%M`

streamer -n ntsc -b 24 -t $1 -s 480x480 -r 29.970 -R 48000 -o stream0.avi -f mjpeg -j 95 -F stereo && mencoder -idx stream0.avi -ovc copy -oac copy -o $2 && rm stream0.avi
clear
exit 0
I tried useing the at command with this script and it did not work. error messages were "garbled time" or "broken token" In this script $1= length of capture and $2 is final file name. I have in the past captured with the at command but everything had to be setup first, I could not add length or file name on the fly. Is there a way to use this with the at command?

thanks in advance
PClinuxOS V.93
AthlonXP 2400
1GB DDR 2100

unSpawn 08-08-2006 06:05 PM

I tried useing the at command with this script and it did not work. error messages were "garbled time" or "broken token"
The script will work. Error messages like "garbled time" just means you didn't tell "at" the right time format to run the script like:
at -f scriptname now
at -f scriptname now + 10 min
at -f scriptname 23:01
at -f scriptname tomorrow
at -f scriptname 23:01 10.08.2006

lpn1160 08-08-2006 08:34 PM

I guess I didn't make myself clear, yes I know all those commands and They work fine, but what about a script that needs input parameters. This doesn't work

./ at -f film_cap 20:00 1:45:00 the_sixth_sense

1:45:00 being the length of time I want to capture,the_sixth_sense=being the file name of the output.

unSpawn 08-09-2006 08:38 AM

what about a script that needs input parameters.
Next time if you ask something phrase it like a question. Here's how:
Code:

#!/bin/sh
# Queue capture job using At
progn="capq"; capdir=~/caps; args=("$@"); argn=${#args[@]}
__help() { echo "${progn}: capturename duration at-timespec"; exit 1; }
__chkTime() { echo "${args[$1]}"|grep -q"[0-9]\{2\}:[0-9]\{2\}" || { echo "${progn} [FATAL]: wrong time format." && exit 127; }; }

# Check args
if [ "$argn" -lt "3" -o "$argn" -gt "5" ]; then echo "${progn} [FATAL]: not enough args."; __help; fi

# Check duration timespec
 __chkTime 1

# At time and date
cap="${args[0]}"; len="${args[1]}"; unset args[0] args[1]
args=(${args[@]}); case "${#args[@]}" in
1) __chkTime 0; time="${args[0]}";;
2) __chkTime 0; time="${args[0]}"; date="${args[1]}";;
0|*) __help;; esac

# Start job one minute in advance (for setup, load, app startup, whatever)
time_h="${time:0:2}"; time_m="${time:3:2}"
case "$time_m" in 00) time_m="59"
case "$time_h" in 00) time_h="23";; *) time_h=$[${time:0:2}-1];; esac;;
*)  time_m=$[${time:3:2}-1];; esac
if [ ${#time_m} = "1" ]; then time_m="0${time_m}"; fi
if [ ${#time_h} = "1" ]; then time_h="0${time_h}"; fi
starttime="${time_h}:${time_m}"

# Use tempfile for dumping at job
t="/tmp/${progn}.at.$$"; if [ -f "$t" ]; then rm -f "$t"; fi
cat <<EOC > "$t"
TMPDIR=\$(mktemp -td ${progn}.XXXXXXXXXX) && {
 streamer -n ntsc -b 24 -t ${time} -s 480x480 -r 29.970 -R 48000 \
 -o "\${TMPDIR}/stream0.avi" -f mjpeg -j 95 -F stereo &&\
 mencoder -idx "\${TMPDIR}/stream0.avi" -ovc copy -oac copy -o "${capdir}/${cap}.avi"
 cd; rm -rf "\${TMPDIR}"
}
EOC
#...and clean up
at -f "$t" "$starttime" "$date"; rm -f "$t"

exit 0

This script accepts "capturename duration at-timespec" params, where at-timespec can be queued as HH:MM or HH:MM DD.MM.YYYY. YMMV(VM).


All times are GMT -5. The time now is 05:20 AM.