aMule Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're back! (IN POG FORM)

Author Topic: BASH script to restart aMule when lost connection  (Read 2936 times)

telefono

  • Newbie
  • Karma: 1
  • Offline Offline
  • Posts: 1
BASH script to restart aMule when lost connection
« on: October 15, 2010, 09:32:11 AM »

Sometimes aMule lost the connection and not reconnects automtically (that's happen when it's running after a few long days) . I made an BASH script for linux, that checks if aMule lost the connection and if yes, restart the aMule daemon.

The script simple checks if not downloading and if the total sources is less than 50, then restart.

In order to use the script, you need to put it in the folder /etc/cron.hourly/ and call it "amulereset" (without any .sh or any, because it only found with simple names)

Quote
sudo touch /etc/cron.hourly/amulereset

the result will be /etc/cron.hourly/amulereset

set some permissions:

Quote
sudo chmod 755  /etc/cron.hourly/amulereset

And...

Quote
sudo gedit  /etc/cron.hourly/amulereset

then copy & paste the follow script:

Quote
#!/bin/bash

# some settings
host=localhost
port=4712
pass=YOUPASSWORD

# if the clients on quee is lees than the setted number, restart (if not downloading)
minClientOnQuee=50

#cheking the status
r=`amulecmd -h $host -p $port -P $pass -c status`

#retrieving info
download=`echo $r | grep -o 'Download: .* Up' | sed -e 's/Download: //' -e 's/ > Up//' | sed -e 's/Download: //' -e 's/ kB\/s//' | sed -e 's/Download: //' -e 's/ bytes\/sec//'`
upload=`echo $r | grep -o 'Upload: .* Cl' | sed -e 's/Upload: //' -e 's/ kB\/s > Cl//'`
ed2k=`echo $r | grep -o 'eD2k: .* Kad' | sed -e 's/eD2k: //' -e 's/ > Kad//'`
kad=`echo $r | grep -o 'Kad: .* Dow' | sed -e 's/Kad: //' -e 's/ > Dow//'`
clientsOnQuee=`echo $r | grep -o 'Clients in queue: .* > Tot' | sed -e 's/Clients in queue: //' -e 's/ > Tot//'`
totalSources=`echo $r | grep -o 'Total sources: .*' | sed -e 's/Total sources: //' -e 's/ //'`

#some echo's for debug
echo "Download : $download"
echo "Upload   : $upload"
echo "clientsOnQuee : $clientsOnQuee"
echo "totalSources : $totalSources"

# only if not downloading
if [ "$download" = 0 ]
then

    if [ "$clientsOnQuee" -lt "$minClientOnQuee" ]
    then
        /etc/init.d/amule-daemon restart
        exit
    fi

fi

exit

i hope this help somebody  ;D
« Last Edit: October 15, 2010, 09:36:38 AM by telefono »
Logged