先谢过各位大哥?
以上问题已解决
还有两个小问题问各位大哥的
1,怎样另它每次登录自动运行阿?
2我不是用root登录的,所以每次脚本都会问我密码,可不可以不问密码但又不把密码写在脚本上呢?
因为密码的原故每次都要打开一个终端,不好看
以下是脚本
#!/bin/bash
ip_seg="172.18.44"
default_gw="172.18.44.254"
over_time=3
netmask="255.255.255.0"
sleep=2
target="202.108.22.5"
count=3
while :; do
sleep $sleep
ping -c $count $target -W $over_time
[ $? -eq 0 ] && continue
while :; do
# clear the configuration of the net card
sudo ifconfig eth0 down
# configure the ipaddress of the eth0
sudo ifconfig eth0 \
$ip_seg.$(($RANDOM /130 +2)) \
netmask $netmask \
up
echo "######## ip已经更改可运行configuration命令查找现有ip ########"
# configure the default gateway
sudo route add default gw $default_gw
# test the new configuration
ping -c 1 $default_gw -W 2
sleep 1
ping -c 1 $default_gw -W 2
# if work, finish
[ $? -eq 0 ] && break
done
done
自动换ip的小脚本,完成,还有2个问题要请教。
- snakexox
- 帖子: 66
- 注册时间: 2007-12-08 20:21
- 来自: 广州
自动换ip的小脚本,完成,还有2个问题要请教。
上次由 snakexox 在 2007-12-11 21:47,总共编辑 1 次。
-
- 帖子: 66
- 注册时间: 2007-12-06 9:14