harakiri576
29-04-2007, 11:43
Hey,
I think some might find the following script useful. It runs on my wl500g to do all the extra stuff I'd like it to do. I don't think you should/could use it out of the box, but I think it contains some good ideas and pointers on how to do custom stuff.
What it does:
- sets upload limit to unlimited if all the desktops are turned off (for faster bittorrent downloads)
- resets wlan every half day (if no wlan host is up)
- chowns incoming directory to avoid right problems with nfs
- restarts thttpd if it's gone
- start bittorrent downloads if a torrent file is found in the incoming directory
#!/bin/sh
export PATH=/sbin:/bin/:/usr/sbin:/usr/bin:/usr/local/sbin
LOGFILE=/tmp/hddspin.log
ALIVEFILE=/opt/tmp/.alive
IN_SSH=/usr/local/root
INCOMING=/opt/deb/store/incoming
PICKEDUP=/opt/tmp
BANDWIDTH=DAY
BWNUM=0
CHOWN_COUNT=0
WLAN_COUNT=0
EXTIF=`cat /usr/local/sbin/uplink_if`
BRUIN=10.0.1.1
KITTEN=10.0.1.2
bwday() {
if [ $BANDWIDTH = NIGHT ]; then
echo "`date` BANDWIDTH DAY" >>$LOGFILE
/usr/local/sbin/wshaper start $EXTIF 3400 240 day
BANDWIDTH=DAY
fi
}
bwnight() {
if [ $BANDWIDTH = DAY ]; then
echo "`date` BANDWIDTH NIGHT" >>$LOGFILE
/usr/local/sbin/wshaper start $EXTIF 3400 240 night
BANDWIDTH=NIGHT
fi
}
echo "`date` HDDSPIN STARTED" >>$LOGFILE
cd /
while true; do
WLAN_UP=0
ANY_UP=0
# PING
for i in `fping -r1 -a 10.0.1.1 10.0.1.2 2>&1`; do
if [ $i = $KITTEN ]; then
WLAN_UP=1;
fi
ANY_UP=1;
done
# WLAN RESET
if [ $WLAN_UP = 0 ] && [ $WLAN_COUNT -gt 720 ]; then
wl radio off
sleep 1
wl radio on
WLAN_COUNT=0
else
let WLAN_COUNT=$WLAN_COUNT+1
fi
# BANDWIDTH
if [ $ANY_UP -eq 1 ]; then
bwday
BWNUM=0
else
let BWNUM=$BWNUM+1
if [ $BWNUM -gt 4 ]; then
bwnight
fi
fi
# CHOWN
let CHOWN_COUNT=$CHOWN_COUNT+1
if [ $CHOWN_COUNT -gt 15 ]; then
chown -R 1001.50 $INCOMING
CHOWN_COUNT=0
# HDD SPINON
touch $ALIVEFILE >/dev/null 2>&1
fi
# THTTPD
if ! pidof thttpd >/dev/null 2>&1; then
echo "`date` THTTPD IS GONE; RESTARTING" >>$LOGFILE
/opt/sbin/thttpd -C /opt/etc/thttpd.conf
fi
# TORRENT - csak ha nem fut
if ! pidof enhanced-ctorrent >/dev/null 2>&1; then
# es nem foglalt a 6882-es port
if ! netstat -t -n | grep 10.0.0.10:6882 >/dev/null 2>&1; then
# es van felszednivalo file
if [ "`ls ${IN_SSH}/*.torrent ${INCOMING}/*.torrent 2>/dev/null`" ]; then
mv ${IN_SSH}/*.torrent ${INCOMING}/ >/dev/null 2>&1
# feldolgozas
FILE="`ls -1 ${INCOMING}/*.torrent 2>/dev/null | head -1`"
echo "`date` PROCESSING $FILE" >>$LOGFILE
mv $FILE $PICKEDUP
cd $INCOMING
BFILE="`basename \"${FILE}\"`"
nice /opt/bin/enhanced-ctorrent -E 1.1 -p 6882 -C 4 "${PICKEDUP}/${BFILE}" >${BFILE}.log 2>&1 </dev/null &
cd /
fi
fi
fi
sleep 60
done
I think some might find the following script useful. It runs on my wl500g to do all the extra stuff I'd like it to do. I don't think you should/could use it out of the box, but I think it contains some good ideas and pointers on how to do custom stuff.
What it does:
- sets upload limit to unlimited if all the desktops are turned off (for faster bittorrent downloads)
- resets wlan every half day (if no wlan host is up)
- chowns incoming directory to avoid right problems with nfs
- restarts thttpd if it's gone
- start bittorrent downloads if a torrent file is found in the incoming directory
#!/bin/sh
export PATH=/sbin:/bin/:/usr/sbin:/usr/bin:/usr/local/sbin
LOGFILE=/tmp/hddspin.log
ALIVEFILE=/opt/tmp/.alive
IN_SSH=/usr/local/root
INCOMING=/opt/deb/store/incoming
PICKEDUP=/opt/tmp
BANDWIDTH=DAY
BWNUM=0
CHOWN_COUNT=0
WLAN_COUNT=0
EXTIF=`cat /usr/local/sbin/uplink_if`
BRUIN=10.0.1.1
KITTEN=10.0.1.2
bwday() {
if [ $BANDWIDTH = NIGHT ]; then
echo "`date` BANDWIDTH DAY" >>$LOGFILE
/usr/local/sbin/wshaper start $EXTIF 3400 240 day
BANDWIDTH=DAY
fi
}
bwnight() {
if [ $BANDWIDTH = DAY ]; then
echo "`date` BANDWIDTH NIGHT" >>$LOGFILE
/usr/local/sbin/wshaper start $EXTIF 3400 240 night
BANDWIDTH=NIGHT
fi
}
echo "`date` HDDSPIN STARTED" >>$LOGFILE
cd /
while true; do
WLAN_UP=0
ANY_UP=0
# PING
for i in `fping -r1 -a 10.0.1.1 10.0.1.2 2>&1`; do
if [ $i = $KITTEN ]; then
WLAN_UP=1;
fi
ANY_UP=1;
done
# WLAN RESET
if [ $WLAN_UP = 0 ] && [ $WLAN_COUNT -gt 720 ]; then
wl radio off
sleep 1
wl radio on
WLAN_COUNT=0
else
let WLAN_COUNT=$WLAN_COUNT+1
fi
# BANDWIDTH
if [ $ANY_UP -eq 1 ]; then
bwday
BWNUM=0
else
let BWNUM=$BWNUM+1
if [ $BWNUM -gt 4 ]; then
bwnight
fi
fi
# CHOWN
let CHOWN_COUNT=$CHOWN_COUNT+1
if [ $CHOWN_COUNT -gt 15 ]; then
chown -R 1001.50 $INCOMING
CHOWN_COUNT=0
# HDD SPINON
touch $ALIVEFILE >/dev/null 2>&1
fi
# THTTPD
if ! pidof thttpd >/dev/null 2>&1; then
echo "`date` THTTPD IS GONE; RESTARTING" >>$LOGFILE
/opt/sbin/thttpd -C /opt/etc/thttpd.conf
fi
# TORRENT - csak ha nem fut
if ! pidof enhanced-ctorrent >/dev/null 2>&1; then
# es nem foglalt a 6882-es port
if ! netstat -t -n | grep 10.0.0.10:6882 >/dev/null 2>&1; then
# es van felszednivalo file
if [ "`ls ${IN_SSH}/*.torrent ${INCOMING}/*.torrent 2>/dev/null`" ]; then
mv ${IN_SSH}/*.torrent ${INCOMING}/ >/dev/null 2>&1
# feldolgozas
FILE="`ls -1 ${INCOMING}/*.torrent 2>/dev/null | head -1`"
echo "`date` PROCESSING $FILE" >>$LOGFILE
mv $FILE $PICKEDUP
cd $INCOMING
BFILE="`basename \"${FILE}\"`"
nice /opt/bin/enhanced-ctorrent -E 1.1 -p 6882 -C 4 "${PICKEDUP}/${BFILE}" >${BFILE}.log 2>&1 </dev/null &
cd /
fi
fi
fi
sleep 60
done