Hago publico los script para grabación automatica utilizados en FM La Tribu y FM La Tecno, tambien estuvo en varias radios comunitarias
/etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
* * * * * encoder /usr/local/bin/watchdog-x11.sh > /dev/null 2>&1
29,59 * * * * encoder sleep $(echo 60-$(date '+\%S.\%N') | bc); /usr/local/bin/gbd-corte > /dev/null 2>&1
31,01 * * * * encoder /usr/local/bin/gbd-verificador > /dev/null 2>&1
* * * * * root /usr/local/bin/watchdog-butt.sh > /dev/null 2>&1
#
/usr/local/bin/gbd-corte
#!/bin/bash
source gbd-env
MNUEVO=""
MACTUAL=$(date "+%M")
if [ $MACTUAL -le "29" ]
then
MNUEVO="00"
else
MNUEVO="30"
fi
DESTINOFINAL="$DIRDEST$(date "+%Y-%m")/$(date "+%d")/"
DESTINOTEMPORAL="$DIRTEMP$(date "+%Y-%m-%d-%H-")$MNUEVO/"
AHORA=$(date "+%Y-%m-%d_%H-")$MNUEVO
/bin/mkdir -p $DESTINOTEMPORAL &
/usr/local/bin/gbd-grabando "$DESTINOFINAL" "$AHORA" "$DURACION" "$DESTINOTEMPORAL" &
sleep 1
/bin/touch $DESTINOTEMPORAL$AHORA.$!.lock
[ -d $DESTINOFINAL ] || /bin/mkdir -p $DESTINOFINAL
exit 0
/usr/local/bin/gbd-env
#!/bin/bash
env
export DISPLAY=:0
# Directorio de Destino : formato /folder/to/share/
DIRDEST="/home/encoder/audios/"
# Directorio Temporal
DIRTEMP="/home/encoder/tmp/"
# Tiempo grabacion en segundos
TEMPREC="1800"
# Duracion en segundos
DURACION="30m"
/usr/local/bin/gbd-grabando
#!/bin/bash
source gbd-env
PID="$$"
DESTINO="$1"
NOMBRE="$2"
DURACION="$3"
DIRTEMP="$4"
PARCIAL="$5"
timeout $DURACION /usr/bin/ffmpeg -f pulse -i default -codec:a libmp3lame -qscale:a 5 $DIRTEMP$NOMBRE.mp3
if [ "$PARCIAL" == "PARCIAL" ]
then
exit 0
else
/bin/mv $DIRTEMP$NOMBRE.mp3 $DESTINO/$NOMBRE.mp3
/bin/rm $DIRTEMP$NOMBRE.$PID.lock
/bin/rm -d $DIRTEMP
fi
exit 0
/usr/local/bin/gbd-parcial
#!/bin/bash
sleep $(echo 60-$(date '+%S.%N'))
source gbd-env
MNUEVO=""
DURACION=""
MACTUAL=$(date "+%M")
if [ $MACTUAL -le "29" ]
then
MNUEVO="00"
DURACION=$(echo "(30-$MACTUAL)*60+$(date "+%S")"|bc)
else
MNUEVO="30"
DURACION=$(echo "(60-$MACTUAL)*60+$(date "+%S")"|bc)
fi
DESTINOFINAL="$DIRDEST$(date "+%Y-%m")/$(date "+%d")/"
DESTINOTEMPORAL="$DIRTEMP$(date "+%Y-%m-%d-%H-")$MNUEVO/"
AHORA=$(date "+%Y-%m-%d_%H-")$MACTUAL
/bin/mkdir -p $DESTINOTEMPORAL
/usr/local/bin/gbd-grabando "$DESTINOFINAL" "$AHORA" "$DURACION" "$DESTINOTEMPORAL" "PARCIAL" &
sleep 1
/bin/touch $DESTINOTEMPORAL$AHORA.$!.lock
[ -d $DESTINOFINAL ] || /bin/mkdir -p $DESTINOFINAL
exit 0
/usr/local/bin/gbd-verificador
#!/bin/bash
source gbd-env
MNUEVO=""
MACTUAL=$(date "+%M")
if [ $MACTUAL -le "29" ]
then
MNUEVO="00"
else
MNUEVO="30"
fi
AHORA=$(date "+%Y-%m-%d-%H-")$MNUEVO
DIRECTORIOS=(`ls $DIRTEMP |grep -v $AHORA`)
if [ -z "$DIRECTORIOS" ]
then
echo "no hay directorios por procesar"
exit 0
else
for DIRECTORIO in "${DIRECTORIOS[@]}"
do
SPLIT=""
DESTINO=""
SPLIT=(`echo $DIRECTORIO |awk -F- '{print $1"-"$2"-"$3"_"$4"-"$5}'`)
DESTINO=(`echo $DIRECTORIO |awk -F- '{print $1"-"$2"/"$3"/"}'`)
ARCHIVOS=(`find $DIRTEMP$DIRECTORIO -name '*.mp3' |sort`)
if [ "${#ARCHIVOS[@]}" -ge "2" ]
then
echo "Hay mas de dos archivos"
ARCHIVOSFF=""
echo "#INICIO" > $DIRTEMP$DIRECTORIO/concat.txt
for ARCHIVO in "${ARCHIVOS[@]}"
do
echo "file '$ARCHIVO' " >> $DIRTEMP$DIRECTORIO/concat.txt
done
#UNION=(`cat $ARCHIVOSFF > $DIRDEST$DESTINO$SPLIT.mp3`)
UNION=(`ffmpeg -f concat -safe 0 -i $DIRTEMP$DIRECTORIO/concat.txt -c copy $DIRDEST$DESTINO$SPLIT.mp3`)
echo "se unieron los archivos $ARCHIVOSFF, en $DIRDEST$DESTINO$SPLIT.mp3"
PURGA=(`rm $DIRTEMP$DIRECTORIO/*.lock`)
PURGA=(`rm $DIRTEMP$DIRECTORIO/*.txt`)
PURGA=(`rm $DIRTEMP$DIRECTORIO/*.mp3`)
PURGA=(`rm -d $DIRTEMP$DIRECTORIO`)
else
echo "no hay mas de dos archivos"
MUEVO=(`mv $ARCHIVOS $DIRDEST$DESTINO$SPLIT.mp3`)
PURGA=(`rm $DIRTEMP$DIRECTORIO/*.lock`)
PURGA=(`rm -d $DIRTEMP$DIRECTORIO`)
fi
exit 0
done
fi
exit 0
Anexos
Los siguentes script eran para levantar automaticamente los servicios de VNC y transmision online, no hacen falta para el resto del sistema de grabacion, pero los dejo por si necesitan un watchdon (servicio que se queda esperando que algo pase para levantarlo nuevamente)
butt
#!/bin/bash
for pid in $(pidof -x watchdog-butt.sh ); do
if [ $pid != $$ ]; then
echo "[$(date)] : $0 : Process is already running with PID $pid"
exit 1
fi
done
while :
do
echo "Reiniciando BUTT" | slacktee.sh
/etc/init.d/butt-opus start
done
x11
#!/bin/bash
for pid in $(pidof -x watchdog-x11.sh ); do
if [ $pid != $$ ]; then
echo "[$(date)] : $0 : Process is already running with PID $pid"
exit 1
fi
done
while :
do
echo "AVISO: X11VCN Reiniciado" | slacktee.sh
/usr/bin/x11vnc
done