programmare l'esecuzione automatica di comandi ogni tot di tempo

Linguaggi di programmazione: php, perl, python, C, bash e tutti gli altri.
fobiss
Scoppiettante Seguace
Scoppiettante Seguace
Messaggi: 327
Iscrizione: lunedì 31 dicembre 2007, 19:51

programmare l'esecuzione automatica di comandi ogni tot di tempo

Messaggio 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
Ultima modifica di fobiss il mercoledì 17 settembre 2008, 22:30, modificato 1 volta in totale.
Avatar utente
crap0101
Rampante Reduce
Rampante Reduce
Messaggi: 8242
Iscrizione: martedì 30 ottobre 2007, 6:33
Desktop: LXDE
Distribuzione: Ubuntu 18.04.1 LTS
Sesso: Maschile
Località: TO
Contatti:

Re: programmare l'esecuzione automatica di comandi ogni tot di tempo

Messaggio da crap0101 »

http://www.gnu.org/ http://boinc.berkeley.edu/ http://www.python-it.org/
- Ricorda le ultime parole di suo padre: «Sta' alla larga dalle chiese, figlio. La sola cosa per cui hanno la chiave è il merdaio. E giurami che non porterai mai un distintivo della legge» - W.S. Burroughs
fobiss
Scoppiettante Seguace
Scoppiettante Seguace
Messaggi: 327
Iscrizione: lunedì 31 dicembre 2007, 19:51

Re: programmare l'esecuzione automatica di comandi ogni tot di tempo

Messaggio 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.
Avatar utente
crap0101
Rampante Reduce
Rampante Reduce
Messaggi: 8242
Iscrizione: martedì 30 ottobre 2007, 6:33
Desktop: LXDE
Distribuzione: Ubuntu 18.04.1 LTS
Sesso: Maschile
Località: TO
Contatti:

Re: [RISOLTO] programmare l'esecuzione automatica di comandi ogni tot di tempo

Messaggio 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)
http://www.gnu.org/ http://boinc.berkeley.edu/ http://www.python-it.org/
- Ricorda le ultime parole di suo padre: «Sta' alla larga dalle chiese, figlio. La sola cosa per cui hanno la chiave è il merdaio. E giurami che non porterai mai un distintivo della legge» - W.S. Burroughs
fobiss
Scoppiettante Seguace
Scoppiettante Seguace
Messaggi: 327
Iscrizione: lunedì 31 dicembre 2007, 19:51

Re: [RISOLTO] programmare l'esecuzione automatica di comandi ogni tot di tempo

Messaggio 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?
Avatar utente
crap0101
Rampante Reduce
Rampante Reduce
Messaggi: 8242
Iscrizione: martedì 30 ottobre 2007, 6:33
Desktop: LXDE
Distribuzione: Ubuntu 18.04.1 LTS
Sesso: Maschile
Località: TO
Contatti:

Re: programmare l'esecuzione automatica di comandi ogni tot di tempo

Messaggio 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
http://www.gnu.org/ http://boinc.berkeley.edu/ http://www.python-it.org/
- Ricorda le ultime parole di suo padre: «Sta' alla larga dalle chiese, figlio. La sola cosa per cui hanno la chiave è il merdaio. E giurami che non porterai mai un distintivo della legge» - W.S. Burroughs
fobiss
Scoppiettante Seguace
Scoppiettante Seguace
Messaggi: 327
Iscrizione: lunedì 31 dicembre 2007, 19:51

Re: programmare l'esecuzione automatica di comandi ogni tot di tempo

Messaggio 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.
Avatar utente
crap0101
Rampante Reduce
Rampante Reduce
Messaggi: 8242
Iscrizione: martedì 30 ottobre 2007, 6:33
Desktop: LXDE
Distribuzione: Ubuntu 18.04.1 LTS
Sesso: Maschile
Località: TO
Contatti:

Re: programmare l'esecuzione automatica di comandi ogni tot di tempo

Messaggio da crap0101 »

ah! ero rimasto qualche pagina indietro!  ;D
adesso lo guardo..
http://www.gnu.org/ http://boinc.berkeley.edu/ http://www.python-it.org/
- Ricorda le ultime parole di suo padre: «Sta' alla larga dalle chiese, figlio. La sola cosa per cui hanno la chiave è il merdaio. E giurami che non porterai mai un distintivo della legge» - W.S. Burroughs
Scrivi risposta

Ritorna a “Programmazione”

Chi c’è in linea

Visualizzano questa sezione: 0 utenti iscritti e 5 ospiti