لینوکس و من

کانکت شدن اتوماتیک، بعد از دیسکانکتی

خیلی وقت بود که دنبال این میگشتم که توی لینوکس بشه وقتی disconnect میشی، خودش connect بشه. تا این که اسکریپت جالبی را یافتم.
درمورد دستور sudo هم دقت کنید. اگه شما نیازی بهش ندارین از توی متن برش دارین. بعد میتونین اینو توی startup بذارین، یا هرکاری میخواین باهاش بکنین!
 
آو، راستی، شاید کسی ندونه چه طور میشه چند تا کانکشن مختلف با اسمای مختلف ساخت. چون دستور sudo pppoeconf یه کانکشن میسازه به نام dsl-provider که با pon dsl-provider وصل میشیم.
 
واسه این کار، با کاربر root به این محل عزیمت بفرمایید:
 
/usr/etc/peers
 
خب، حالا اون فایل dsl-provider رو تغییر نام بدین. مثلا night . از این به بعد با دستور pon night وصل میشین. حالا میتونین یه کانکشن دیگه هم بسازین و اسمشو تغییر بدین.
 
درمورد اینترنت  dialup نمیدونم دستور ها چیه. کسی میدونه لطفا بگه.
 
برای دیدن اسکریپت به ادامه مطلب برید
#!/bin/bash
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
PON_WAIT=10
PING_WAIT=10
CHECK_WAIT=10
LOOP_WAIT=60
PING_CHECKS=10
SECOND_CONNECTION_START=3
SECOND_CONNECTION_END=7
FIRST_DSL_PROVIDER=”dsl-provider”
SECOND_DSL_PROVIDER=”fdsl-provider”

Poff() {
Prompt “Terminating all running ppp clients…”
PidResult=$(pidof pppd)
until [ -z "$PidResult" ]; do
poff -a
PidResult=$(pidof pppd)
#	 echo $PidResult
sleep 1
done
echo “done.”
}

Wait() {
if [ -z $1 ]; then
:
else
#	 echo -n “wait for “$1″ seconds…”
i=0
while [ $i -lt $1 ]; do
sleep 1
#	 echo -n $i
let “i++”
done
#	 echo $i
fi
}

Prompt () {
TimeStamp=$(date)
echo “["$TimeStamp"] : “$1
}

DailyStartups () {
skype &
}

AzureusWatch () {
while [ 1 ]
do
azureus >> ~/azureus.log
Prompt “Azureus died. Running again…”
done
}

NightmareStartups () {
#Your-Freedom
#	java -jar ‘/home/ario/Temp/freedom-20100204-01/freedom.jar’ >> ~/freedom.log &
#Azureus
Prompt “Starting Azureus Download manager…”
AzureusWatch &
Prompt “Done.”

#Aria2 script
Prompt “Starting Aria2 script…”
/home/mahedieh/aria2 >> aria2.log &
Prompt “Done.”
}

Connect () {
Poff
Prompt “Running pon “$Dsl”…”
pon $Dsl
Prompt “done.”
}

Main () {
echo
echo “=============================================================”
echo
echo “PPPoE Automation for Ubuntu. By Ario Shahbani.”
echo “This script is brought to you under the terms of GNU Licence.”
echo “And its with no waranty.”
echo “Hope this helps!”
echo “nullevent@yahoo.com”
echo -n “Starting up at: ”
date
echo
echo
echo
Poff
PingResult=1
LastDslNumber=0
while [ 1 ]
do
Hour=$(date +%H)
if [ $Hour -lt $SECOND_CONNECTION_START ] || ! [ $Hour -lt $SECOND_CONNECTION_END ]; then
Dsl=$FIRST_DSL_PROVIDER
DslNumber=1
else
Dsl=$SECOND_DSL_PROVIDER
DslNumber=2
fi
if ! [ $DslNumber -eq $LastDslNumber ]; then
Connect
if [ $DslNumber -eq 1 ]; then
DailyStartups &
else
NightmareStartups &
fi
fi
#	 Prompt “Pinging http://www.google.com...”
for ((g=0; g /dev/null
PingResult=$?
if [ $PingResult -eq 0 ]; then
#	 Prompt “Every thing seems Ok:) but i will check connection soon again.”
Wait $CHECK_WAIT
break
else
Prompt “Oh Ping Failed!…”
Wait $CHECK_WAIT
fi
done
if [ $PingResult -eq 0 ]; then #if connection is normal
Wait $LOOP_WAIT
else	 #if connection is down
Prompt “Ping really failed:( So reconnecting…”
Connect
Wait $PON_WAIT
fi
LastDslNumber=$DslNumber
done
exit 1
}

Main >> ~/autoppp.log

 

دسته:

ترفند

کلیدواژه:

اینترنت