#1 Le 13/07/2012, à 11:03
- Jpmtrax
Problème avec crontab [RESOLU]
Bonjour,
je cherche à automatiser une tâche d'enregistrement audio avec crontab. Problème : cette tâche ne semble pas vouloir démarrer.
En fait, je souhaite simplement que toutes les heures l'ordinateur enregistre une heure de son.
J'ai donc tapé crontab -e et ensuite dans le fichier j'ai mis
0 * * * * arecord -f cd -d 3600 --use-strftime %Y-%m-%d-%Hh-pige
ce qui devrait donner dans mon répertoire /home/user un truc du genre
2012-07-13-11h-pige.wav
sauf que rien ne se passe.
quand je tape la commande dans un shell, ça fonctionne.
quand je mets dans crontab une commande plus simple du genre
0 * * * * arecord -f cd -d 10 test.wav
ça fonctionne.
j'avoue que là, quelque chose m'échappe. Une idée ?
Dernière modification par Jpmtrax (Le 23/07/2012, à 11:04)
Perso : Tour Packard Bell avec Xubuntu 18.04 LTS (32 bits) + 20.04 LTS (64 bits) + Win XP SP3 - Intel Core 2 Extreme X6800 2,93 Ghz - 4 Go Ram / Netbook Packard Bell Dot S avec Lubuntu 16.04 LTS + Win XP SP3 - Intel Atom N450 - 2 Go Ram / Boulot : AMD Ryzen 5 1400 - 8 Go Ram -Xubuntu 18.04 LTS
Hors ligne
#2 Le 13/07/2012, à 11:53
- Jpmtrax
Re : Problème avec crontab [RESOLU]
Bon, j'ai tenté de lancer un script plutôt qu'une commande directement, je vous tiens au courant...
Perso : Tour Packard Bell avec Xubuntu 18.04 LTS (32 bits) + 20.04 LTS (64 bits) + Win XP SP3 - Intel Core 2 Extreme X6800 2,93 Ghz - 4 Go Ram / Netbook Packard Bell Dot S avec Lubuntu 16.04 LTS + Win XP SP3 - Intel Atom N450 - 2 Go Ram / Boulot : AMD Ryzen 5 1400 - 8 Go Ram -Xubuntu 18.04 LTS
Hors ligne
#3 Le 13/07/2012, à 11:55
- Postmortem
Re : Problème avec crontab [RESOLU]
Salut,
Ajoute une redirection à la fin de ta commande afin de voir les éventuels messages d'erreurs :
0 * * * * arecord -f cd -d 3600 --use-strftime %Y-%m-%d-%Hh-pige > /tmp/enregistrement.log 2>&1
Mot' a dit : « Un Hellfest sans Slayer, c'est comme une galette-saucisse sans saucisse ! »
Hors ligne
#4 Le 13/07/2012, à 13:05
- wilco
Re : Problème avec crontab [RESOLU]
Bonjour,
Je ne connais pas la commande arecord, mais coté date ( %Y-%m-%d-%Hh)
ca ne peut pas marcher.
Il te faut introduite la commande date ainsi :
arecord `date +%Y-%m-%d-%Hh`-pige
Intel Core i3-2125, 3,3 GHz / Carte mère : ASUS P8H67-M PRO / 2x 4 Go Mem / Boitier Antec Sonata III 500/ 500 Go (system /Home séparé /Swap) / 1 To / 1 graveur DVD IDE / Ecran 22" / All in one Hp Envy 5540
Hors ligne
#5 Le 13/07/2012, à 13:45
- credenhill
Re : Problème avec crontab [RESOLU]
hello
mettre des \ devant les %
$ man -s 5 crontab
... Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.
...
Hors ligne
#6 Le 13/07/2012, à 15:02
- Postmortem
Re : Problème avec crontab [RESOLU]
hello
mettre des \ devant les %$ man -s 5 crontab ... Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input. ...
Ah oui dis donc !! J'avais jamais fait attention à ça...
Me coucherai moins con ce soir !
Mot' a dit : « Un Hellfest sans Slayer, c'est comme une galette-saucisse sans saucisse ! »
Hors ligne
#7 Le 16/07/2012, à 11:58
- Jpmtrax
Re : Problème avec crontab [RESOLU]
hello
mettre des \ devant les %$ man -s 5 crontab ... Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input. ...
Ah d'accord...
Curieux, Je pensais que le \ ne servait qu'à créer des répertoires ? Donc dans crontab pour qu'une commande comportant un % fonctionne, il faut obligatoirement mettre un \ devant ? mais \ suivi d'un espace je suppose et du % ?
Mais bon cela dit mon script (ou plutôt une adaptation d'un script existant) semble fonctionner... mais pas sûr, encore quelques petites choses à vérifier... je vous tiens au courant..
Perso : Tour Packard Bell avec Xubuntu 18.04 LTS (32 bits) + 20.04 LTS (64 bits) + Win XP SP3 - Intel Core 2 Extreme X6800 2,93 Ghz - 4 Go Ram / Netbook Packard Bell Dot S avec Lubuntu 16.04 LTS + Win XP SP3 - Intel Atom N450 - 2 Go Ram / Boulot : AMD Ryzen 5 1400 - 8 Go Ram -Xubuntu 18.04 LTS
Hors ligne
#8 Le 16/07/2012, à 12:04
- credenhill
Re : Problème avec crontab [RESOLU]
il faut obligatoirement mettre un \ devant ? mais \ suivi d'un espace je suppose et du % ?
non, pas d'espace
* * * * arecord -f cd -d 3600 --use-strftime \%Y-\%m-\%d-\%Hh-pige
Hors ligne
#9 Le 23/07/2012, à 11:03
- Jpmtrax
Re : Problème avec crontab [RESOLU]
Bonjour tout le monde et déjà merci pour votre aide.
Finalement j'ai fait autrement. D'une part j'ai récupéré un script sur internet que j'ai adapté comme ceci :
#!/bin/sh
#
# pige.sh
#
# This is a script that will automatically record a radio audio stream to a .wav file using the arecord program.
#
# arecord program significant options:
#
# -r, --rate=#<Hz> Sampling rate in Hertz. The default rate is 8000 Hertz.
#
# -d, --duration=# Interrupt recording after # seconds.
#
# -c, --channels=# The number of channels. The default is one channel.
#
#####################################################################################################################################
# First we determine today's date and set variables $DAY, $MO and $YR. Also set variable $NOW for current date and time.
DAY=$(date +%d) # set variable $DAY for day
MO=$(date +%m) # set variable $MO for month
YR=$(date +%y) # set variable $YR for year (2 digits)
NOW=$(date) # sets date / time variable $NOW
# Next we determine the current time and set variables $H and $M. Also we set the frequency variable $F.
H=$(date +%H) # set variable $H for hour (24 hour)
M=$(date +%M) # set variable $M for minute
echo $NOW "Enregistrement en cours.. " to audio file $DAY$MO$YR-$H$M-"pige".wav # puts start time entry in record.log
# Edit the following line for the recording duration, examples: -d420 = 420 seconds -d600 = 600 seconds
arecord -d 3599 -f cd /${HOME}/nouveau.wav # Records audio stream for 59 minutes 59(3599 seconds)
lame /${HOME}/nouveau.wav /${HOME}/nouveau.mp3 # convertit fichier en mp3 128kbps stereo
mv /${HOME}/nouveau.mp3 /${HOME}/$DAY$MO$YR-$H$M-"pige".mp3
echo
NOW=$(date) # resets date / time variable $NOW to current time
echo $NOW "Enregistrement terminé de "$DAY$MO$YR-$H$M-$F"pige".mp3 # puts stop recording time entry in record.log
echo
ls -l /${HOME}/$DAY$MO$YR-$H$M-"pige".mp3 # lists output file size and details
echo
echo
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" # puts separation line in record.log
source du script : http://www.w0ch.net/linux/audio_record.htm
ensuite j'ai créé ce fichier pour crontab :
0 * * * * bash /${HOME}/pige.sh >> /${HOME}/verification_pige.log
0 0 1 * * cd /home/pige|find *pige.mp3 -ctime +90 -exec rm {} \;
donc exécution du script toutes les heures avec une écriture vers fichier log et purge automatique au bout de 90 jours.
depuis, plus de problèmes. J'ai mis 3599 secondes au lieu de 3600 parce que visiblement si je ne fais pas ça l'ordi n'a pas le temps de convertir le fichier nouveau.wav en nouveau.mp3 et de recréer un autre nouveau.wav dans la foulée, du coup avec 3600 secondes il ré-écrasait toujours celui qu'il venait de créer..
Voilà merci encore de votre aide, en espérant que ce post soit utile à d'autres...
Perso : Tour Packard Bell avec Xubuntu 18.04 LTS (32 bits) + 20.04 LTS (64 bits) + Win XP SP3 - Intel Core 2 Extreme X6800 2,93 Ghz - 4 Go Ram / Netbook Packard Bell Dot S avec Lubuntu 16.04 LTS + Win XP SP3 - Intel Atom N450 - 2 Go Ram / Boulot : AMD Ryzen 5 1400 - 8 Go Ram -Xubuntu 18.04 LTS
Hors ligne