Pagina 1 di 1
programmare l'esecuzione automatica di comandi ogni tot di tempo
Inviato: mercoledì 17 settembre 2008, 18:41
da fobiss
salve, vorrei sapere lopinione di qualche esperto sulla seguente cosa: ultimamente sto cercando di usare amule ma, dopo un certo tempo, mi va in crash, si chiude e mi tocca riavviarlo, dopo che probabilmente ho perso il posto in coda a chi stavo scaricando. Dato che di solito scarico volumi molto grandi di roba per me rimanere connesso di continuo anche senza la mia sorveglianza, per esempio di notte, sarebbe alquanto agevolante e, dato che non ho trovato soluzione a questo guasto dopo aver postato anche in altri forum, anzi ho letto dello stesso problema rimasto irrisolto mi verrebbe da chiedermi: si può considerare l'idea di fare uno script che, diciamo ogni circa 5-10 minuti, dia sempre il comando "amule" su terminale in modo che, se è ancora aperto non accade nulla, e se invece ha crashato si riavvii di nuovo? Quello che mi chiedo è se la cosa non crei danni o rallentamenti inutili al sistema a lungo andare (parlo dell'ordine di giorni), perchè se fosse possibile mi aiuterebbe almeno ad aggirare il problema. Se la cosa fosse fattibile accetto suggerimenti su come concretizzare la cosa, dato che di programmazione ne so poco nulla.
Grazie
Re: programmare l'esecuzione automatica di comandi ogni tot di tempo
Inviato: mercoledì 17 settembre 2008, 19:57
da crap0101
Re: programmare l'esecuzione automatica di comandi ogni tot di tempo
Inviato: mercoledì 17 settembre 2008, 20:27
da fobiss
Grazie, in ogni caso non avrei saputo che parole chiave usare per cercare perchè non sapevo neanche bene come esprimermi, dato che come ho già detto di programmazione ne so poco nulla.
Re: [RISOLTO] programmare l'esecuzione automatica di comandi ogni tot di tempo
Inviato: mercoledì 17 settembre 2008, 20:47
da crap0101
eh! anch' io l' avevo trovato per caso qualche tempo fa (anzi, l' aveva trovato un altro utente che cercava la stessa cosa)
Re: [RISOLTO] programmare l'esecuzione automatica di comandi ogni tot di tempo
Inviato: mercoledì 17 settembre 2008, 22:27
da fobiss
Ascolta già che ci sono chiedo anche a te, anche se ho già postato anche il quella discussione (non so se qualcuno guarderà, dato che mi pare un po' datata): ho provato a usare l'ultmo script postato nella seconda pagina e amule funzia bene, ma sul terminale mi vengono fuori questi messaggi che non so cosa significhino e mi sembra che non tutto vada per il verso giusto:
Codice: Seleziona tutto
roberto@roberto-laptop:~$ ./check_amule.sh
Starting /usr/bin/amule...grep: /home/roberto/.eMule: Nessun file o directory
grep: /home/roberto/.eMule: Nessun file o directory
grep: /home/roberto/.eMule: Nessun file o directory
grep: /home/roberto/.eMule: Nessun file o directory
cp: impossibile fare stat di `/home/roberto/.eMule': Nessun file o directory
mv: impossibile fare stat di `/home/roberto/.amule.tmp': Nessun file o directory
./check_amule.sh: 97: mail: not found
done!
Initialising aMule
Checking if there is an instance already running...
No other instances are running.
ListenSocket: Ok.
Loading temp files from /home/roberto/.aMule/Temp.
Loading PartFile 174 of 174
All PartFiles Loaded.
Adding file /home/roberto/.aMule/Temp/134.part.met to shares
Adding file /home/roberto/.aMule/Temp/136.part.met to shares
Adding file /home/roberto/.aMule/Temp/137.part.met to shares
Adding file /home/roberto/.aMule/Temp/138.part.met to shares
Adding file /home/roberto/.aMule/Temp/139.part.met to shares
Adding file /home/roberto/.aMule/Temp/142.part.met to shares
Adding file /home/roberto/.aMule/Temp/115.part.met to shares
Adding file /home/roberto/.aMule/Temp/119.part.met to shares
Adding file /home/roberto/.aMule/Temp/124.part.met to shares
Adding file /home/roberto/.aMule/Temp/130.part.met to shares
Adding file /home/roberto/.aMule/Temp/131.part.met to shares
Adding file /home/roberto/.aMule/Temp/195.part.met to shares
Adding file /home/roberto/.aMule/Temp/197.part.met to shares
Adding file /home/roberto/.aMule/Temp/199.part.met to shares
Adding file /home/roberto/.aMule/Temp/159.part.met to shares
Adding file /home/roberto/.aMule/Temp/045.part.met to shares
Adding file /home/roberto/.aMule/Temp/051.part.met to shares
Adding file /home/roberto/.aMule/Temp/008.part.met to shares
Adding file /home/roberto/.aMule/Temp/010.part.met to shares
Adding file /home/roberto/.aMule/Temp/011.part.met to shares
Adding file /home/roberto/.aMule/Temp/012.part.met to shares
Adding file /home/roberto/.aMule/Temp/015.part.met to shares
Adding file /home/roberto/.aMule/Temp/016.part.met to shares
Adding file /home/roberto/.aMule/Temp/017.part.met to shares
Adding file /home/roberto/.aMule/Temp/019.part.met to shares
Adding file /home/roberto/.aMule/Temp/022.part.met to shares
Adding file /home/roberto/.aMule/Temp/029.part.met to shares
Adding file /home/roberto/.aMule/Temp/030.part.met to shares
Adding file /home/roberto/.aMule/Temp/092.part.met to shares
Adding file /home/roberto/.aMule/Temp/100.part.met to shares
Adding file /home/roberto/.aMule/Temp/109.part.met to shares
Adding file /home/roberto/.aMule/Temp/070.part.met to shares
Adding file /home/roberto/.aMule/Temp/078.part.met to shares
** (amule:18784): WARNING **: Invalid borders specified for theme pixmap:
/home/roberto/.themes/BlueSpace_II/gtk-2.0/shadows/frame1.png,
borders don't fit within the image
dopo un po' è venuto fuori anche questo:
Codice: Seleziona tutto
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
Invalid Kad tag; type=0x89 name=
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
./check_amule.sh: 97: [[: not found
non è che magari sai aiutarmi?
Re: programmare l'esecuzione automatica di comandi ogni tot di tempo
Inviato: mercoledì 17 settembre 2008, 22:47
da crap0101
questo?
Codice: Seleziona tutto
#!/bin/bash
while [ 1 ]
do
amule
if test $? -eq 0
then
exit 1
fi
done
nel frattempo chiudi amule, così si parte da "pulito"
poi lancialo con
./check_amule.sh &
con la `&` in fondo
Re: programmare l'esecuzione automatica di comandi ogni tot di tempo
Inviato: giovedì 18 settembre 2008, 0:48
da fobiss
veramente no, mi riferivo a questo:
Codice: Seleziona tutto
#!/bin/sh
# ******************************
# *** program restart script ***
# ******************************
#
# Written by Fabio Dellutri <fdellutri@tiscali.it>
#
# This script starts $PROGRAM and restart it if it dies unexpectedly.
# Also it tries to check if $PROGRAM is in stale state and restart it
#
# Last modification: 29 October 2003
# ***************************
# ** Configuration Section **
# ***************************
PROGNAME="amule"
PROGRAM="/usr/local/bin/amule"
WAIT_INTERVAL=10s
STALE_WAIT_INTERVAL=3m
TCPPORT1=4662
TCPPORT2=4665
TEMP="/your/home/.$PROGNAME.tmp"
CONF="/your/home/.eMule"
MAILTO="utente@provider.it"
# *****************
# ** Script Code **
# *****************
#
# This function writes on $CONF file the right port doing a round-robin on the $TCPPORT*
#
upgrade_port() {
if ! [ -z $(grep Port=${TCPPORT1} ${CONF} | awk -F'=' '{print $2}' | head -1) ]; then
sed -e "s/Port=${TCPPORT1}/Port=${TCPPORT2}/" ${CONF} > ${TEMP}
elif ! [ -z $(grep Port=${TCPPORT2} ${CONF} | awk -F'=' '{print $2}' | head -1) ]; then
sed -e "s/Port=${TCPPORT2}/Port=${TCPPORT3}/" ${CONF} > ${TEMP}
elif ! [ -z $(grep Port=${TCPPORT3} ${CONF} | awk -F'=' '{print $2}' | head -1) ]; then
sed -e "s/Port=${TCPPORT3}/Port=${TCPPORT4}/" ${CONF} > ${TEMP}
elif ! [ -z $(grep Port=${TCPPORT4} ${CONF} | awk -F'=' '{print $2}' | head -1) ]; then
sed -e "s/Port=${TCPPORT4}/Port=${TCPPORT1}/" ${CONF} > ${TEMP}
fi
cp ${CONF} ${CONF}_bak
mv ${TEMP} ${CONF}
}
#
# Test if the program exist and it is executable
#
if test ! -x $PROGRAM
then
echo "The file $PROGRAM does not exist or is not executable!"
exit 1
fi
#
# Main script body
#
while true
do
# Test if $PROGRAM is dead
NUMPROCS=$(ps xa | grep -v "grep" | grep -c $PROGRAM)
if test "$NUMPROCS" -lt "1"
then
echo -n "Starting $PROGRAM..."
# Check for port
upgrade_port
# Run $PROGRAM
$PROGRAM &> /dev/null &
# Send Email notification
if [ ${MAILTO} ]; then
echo "$PROGNAME restarted on `date`." | mail -s "$PROGNAME restarted on `date`" ${MAILTO}
fi
echo " done!"
fi
# Test if program is in stale state
T1=$(ps ax | grep -v grep | grep $PROGRAM | awk '{print $4}')
sleep $STALE_WAIT_INTERVAL
T2=$(ps ax | grep -v grep | grep $PROGRAM | awk '{print $4}')
if [[ "${T1}" == "${T2}" ]]; then
# $PROGRAM is in "stale" state
killall $PROGRAM
if [ ${MAILTO} ]; then
echo "$PROGNAME was found in stale on `date`." | mail -s "$PROGNAME in stale on `date`" ${MAILTO}
fi
fi
# wait for $WAIT_INTERVAL seconds
sleep $WAIT_INTERVAL
done
e comunque quello che volevo non era semplicemente impedire che il terminale mi mostrasse i messaggi, ma capire il motivo per cui compaiono, dato che evidentemente sono dovuti a malfunzionamenti di altri comandi secondari, come quelli fra le prime circa 15 righe del programma, fra quello che, se non erro, dovrebbe mandare una mail a un indirizzo a impostare per indicare il momento in cui avviene un crash, che per me sarebbe molto interessante.
Re: programmare l'esecuzione automatica di comandi ogni tot di tempo
Inviato: giovedì 18 settembre 2008, 0:50
da crap0101
ah! ero rimasto qualche pagina indietro!

adesso lo guardo..