闲着挂个拨号的。。。

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
qqttdh
帖子: 896
注册时间: 2007-07-20 22:15

闲着挂个拨号的。。。

#1

帖子 qqttdh » 2008-06-29 8:07

代码: 全选

#!/bin/bash
poff -a
echo adsl on\/off
#read temp
if(test $1 = on)then
a=`route -n |wc -l`
#echo $a
while (test 1)do
poff -a
pon dsl-provider
#echo $b
sleep 1
b=`route -n |wc -l`
if(($b > $a));then
zenity  --info --text="已连接"
exit
fi
done
elif (test $1 = off)then
#poff
zenity  --info --text="已断开"
fi
exit
头像
qqttdh
帖子: 896
注册时间: 2007-07-20 22:15

#2

帖子 qqttdh » 2008-06-29 8:15

代码: 全选

#!/bin/bash
poff -a
echo adsl on\/off
#read temp
if(test $1 = on)then
while (test 1)do
poff -a
pon dsl-provider
#echo $b
sleep 1
b=`ifconfig |grep ppp|wc -l`
if(($b > 0));then
zenity  --info --text="已连接"
exit
fi
done
elif (test $1 = off)then
#poff
zenity  --info --text="已断开"
fi
exit
头像
qqttdh
帖子: 896
注册时间: 2007-07-20 22:15

#3

帖子 qqttdh » 2008-06-29 8:18

代码: 全选

#!/bin/bash
echo adsl on\/off
#read temp
if(test $1 = on)then
#a=`route -n |wc -l`
#echo $a
while (test 1)do
b=`ifconfig |grep ppp|wc -l`
if(($b > 0));then
zenity  --info --text="已连接"
exit
fi
pon dsl-provider
#echo $b
sleep 1
#b=`route -n |wc -l`
done
elif (test $1 = off)then
#poff
poff -a
zenity  --info --text="已断开"
fi
exit
头像
qqttdh
帖子: 896
注册时间: 2007-07-20 22:15

#4

帖子 qqttdh » 2008-06-29 22:22

再来更新一下

代码: 全选

#!/bin/bash
#echo adsl on\/off
a=0
if(zenity --question --text="建立拨号?")then
a=on
elif(zenity --question --text="断开连接?")then
a=off
fi

if(test $a = on)then
#a=`route -n |wc -l`
#echo $a
while (test 1)do
b=`ifconfig |grep ppp|wc -l`
if(($b > 0));then
zenity  --info --text="已连接"
exit
fi
pon dsl-provider
#echo $b
sleep 2
#b=`route -n |wc -l`
done
elif (test $a = off)then
#poff
poff -a
zenity  --info --text="已断开"
fi
exit
头像
qqttdh
帖子: 896
注册时间: 2007-07-20 22:15

#5

帖子 qqttdh » 2008-06-30 6:37

代码: 全选

#!/bin/bash
#a=on建立拨号/a=off断开连接
a=0
if(zenity --question --text="建立拨号?")then
a=on
elif(zenity --question --text="断开连接?")then
a=off
fi

if(test $a = on)then
#重试次数t
t=20
for((i=0;i<=$t;i++));do
b=`ifconfig |grep ppp|wc -l`
if(($b > 0));then
zenity  --info --text="已连接"
exit
fi
#尝试建立连接
pon dsl-provider
sleep 2
if(($i == $t));then
if(zenity --question --text="超过重试$t次数是否继续?")then
i=0
fi
fi
echo $i
done
elif (test $a = off)then
#断开连接
poff -a
zenity  --info --text="已断开"
fi
exit
头像
qqttdh
帖子: 896
注册时间: 2007-07-20 22:15

#6

帖子 qqttdh » 2008-07-11 7:40

终端中的应用程序

代码: 全选

#!/bin/bash
#a=on建立拨号/a=off断开连接
a=0
b=`ifconfig |grep ppp|wc -l`
#配置账号
if(zenity --question --text="配置账号密码?")then
sudo pppoeconf
#判断连接是否建立
elif(($b > 0));then
if(zenity --question --text="断开连接?")then
a=off
fi
elif(zenity --question --text="建立拨号?")then
a=on
fi

if(test $a = on)then
#重试次数t
t=0
#for((i=1;i<=$t;i++));do
for((i=1;;i++));do
echo 第$i次拨号。。。
#尝试建立连接
pon dsl-provider
sleep 2
if(($i == $t));then
if(zenity --question --text="超过重试$t次数是否继续?")then
i=1
fi
fi
#判断连接是否建立
b=`ifconfig |grep ppp|wc -l`
if(($b > 0));then
zenity  --info --text="已连接"
exit
fi
done
elif (test $a = off)then
#断开连接
poff -a
zenity  --info --text="已断开"
fi
exit
头像
qqttdh
帖子: 896
注册时间: 2007-07-20 22:15

Re: 闲着挂个拨号的。。。

#7

帖子 qqttdh » 2008-09-26 10:33

继续改进。。。

代码: 全选

#!/bin/bash
#a=on建立拨号/a=off断开连接
a=0
b=`ifconfig |grep ppp|wc -l`
#配置账号
#if(zenity --question --text="配置账号密码?")then
#sudo pppoeconf
#判断连接是否建立
if(($b > 0));then
if(zenity --question --text="断开连接?")then
a=off
fi
#elif(zenity --question --text="建立拨号?")then
else
a=on
e=`route -n|grep eth0|wc -l`
w=`route -n|grep wlan0|wc -l`
fi

if(test $a = on)then
#重试次数t
t=0
#for((i=1;i<=$t;i++));do
for((i=1;;i++));do
#echo 第$i次拨号。。。
#尝试建立连接
if(($w > 0));then
echo 第$i次拨号。。。wlan0
pon dsl-provider-wlan0
elif(($e > 0));then
echo 第$i次拨号。。。eth0
pon dsl-provider-eth0
fi
sleep 2
if(($i == $t));then
if(zenity --question --text="超过重试$t次数是否继续?")then
i=1
fi
fi
#判断连接是否建立
b=`ifconfig |grep ppp|wc -l`
if(($b > 0));then
#zenity  --info --text="已连接"
exit
fi
done
elif (test $a = off)then
#断开连接
poff -a
b=`ifconfig |grep ppp|wc -l`
if(($b < 1));then
#zenity  --info --text="已断开"
exit
else
zenity  --info --text="断开失败"
fi
fi
exit
头像
qqttdh
帖子: 896
注册时间: 2007-07-20 22:15

Re: 闲着挂个拨号的。。。

#8

帖子 qqttdh » 2008-10-14 10:18

继续继续。。。

代码: 全选

#!/bin/sh
#a=on建立拨号/a=off断开连接
a=0
b=`ifconfig |grep ppp|wc -l`
#配置账号
#if(zenity --question --text="配置账号密码?")then
#sudo pppoeconf
#判断连接是否建立
if [ $b != 0 ];then
if(zenity --question --text="断开连接?")then a=off
fi
else a=on
while [ ture ];do
w=`route -n|grep -c wlan0`
if [ $w != 0 ];then echo "use wlan0";break;fi
e=`route -n|grep -c eth0`
if [ $e != 0 ];then echo "use eth0";break;fi
echo "no lan...wating"
sleep 2 & while [ -e /proc/$! ];do echo -n '.';sleep 1;done
done
fi

if [ $a = on ];then
#重试次数t
t=0
i=0
while [ ture ];do
i=$(($i + 1))
#尝试建立连接
if [ $w != 0 ];then
echo 第$i次拨号。。。wlan0
pon dsl-provider-wlan0
elif [ $e != 0 ];then
echo 第$i次拨号。。。eth0
pon dsl-provider-eth0
fi
sleep 0.1
if [ $i = $t ];then
if(zenity --question --text="超过重试$t次数是否继续?")then
i=1
fi
fi
#判断连接是否建立
b=`ifconfig |grep ppp|wc -l`
if [ $b != 0 ];then
echo "已连接"
exit
fi
sleep 2.9&while [ -e /proc/$! ];do echo -n '.';sleep 1;done
done

elif [ $a = off ];then
#断开连接
poff -a
b=`ifconfig |grep ppp|wc -l`
if [ $b = 0 ];then
echo "已断开"
exit
else
zenity  --info --text="断开失败"
fi
fi
exit
头像
qqttdh
帖子: 896
注册时间: 2007-07-20 22:15

Re: 闲着挂个拨号的。。。

#9

帖子 qqttdh » 2008-10-20 8:07

...结合conky...定时检查拨号网络

代码: 全选

#!/bin/sh
b=`route -n|grep -c ppp`
w=`route -n|grep -c wlan0`
e=`route -n|grep -c eth0`

if [ $b = 0 ];then

if [ $w != 0 ];then
p=`pon dsl-provider-wlan0`
elif [ $e != 0 ];then
p=`pon dsl-provider-eth0`
fi

elif [ $w = 0 ]&&[ $e = 0 ];then
poff -a
fi

b=`route -n|grep -c ppp`
if [ $b = 0 ];then
echo OFF
else
echo ON
fi
zcc
帖子: 1
注册时间: 2008-10-10 0:58

Re: 闲着挂个拨号的。。。

#10

帖子 zcc » 2008-11-02 15:02

好帖 顶一个
Codefresher
帖子: 62
注册时间: 2008-04-13 9:39
来自: china

Re: 闲着挂个拨号的。。。

#11

帖子 Codefresher » 2008-11-08 10:28

这个代码的缩进还是有待改进呀
Linux c ,it is now my favourite.
回复