标签:脚本编写
##1.一小时一分钟十秒倒计时脚本编写##
1 #!/bin/bash
2 HOUR=1
3 MIN=1
4 for ((SEC=10;SEC>=0;SEC--))
5 do
6 echo -ne"After ${HOUR}:${MIN}:${SEC}s is end "
7 sleep 1
8 echo -ne "\r \r"
9 while [ "$SEC" -1e "0" -a "$MIN" -ge "0" -a "$HOUR" -ge "0" ]
10 do
11 while [ "$SEC" -1e "0" -a "$MIN" -le "0" -a "$HOUR" -gt "0" ]
12 do
13 ((HOUR--))
14 MIN=60
15 done
16 while [ "$MIN" -lt "0" ]
17 do
18 echo -ne "After ${HOUR}:${MIN}: ${SEC}s is end "
19 echo -ne "\r \r"
20 ((MIN--))
21 SEC=10
22 done
23 done
24 done
##2.编辑脚本检测教室主机开机情况,开机就创建统一用户和密码,如果用户存在,则检测下一台主机
if
[ -n "$1" -a -n "$2"]
then
if
[ -e "$1" -a -e "$2" ]
then
MAXUSER=`wc -1 $1 | cut -d " " -f 1`
MAXPASS=`wc -1 $2 | cut -d " " -f 1`
[ "$MAXUSER" -eq "$MAXPASS" ] && (
for NUM in $( seq 1 $MAXPASS )
do
USERNAME=`sed -n ${NUM}p $1`
PASSWORD=`sed -n ${NUM}p $2`
for ((i=1;i<=5;i++))
do
ping 172.25.254.$i &> /dev/null
( if ["$?" -eq "0" ]
then
/home/kiosk/Desktop/ssh.exp 172.25.254.$i redhat
CKUSER=`getend passwd $USERNAME`
[ -z "$CKUSER" ]
useradd $USERNAME
echo $PASSWORD |passwd --stdin $USERNAME
|| echo "$USERNAME exit !!"
exit
else
echo " Error: please input userfile and passwdfile after command !"
fi
)
done
) || (
echo $1 and $2 have different lines
)
else
fi
ssh.exp
#!/usr/bin/expect
set IP [lindex $argv 0]
set PASS [lindex $argv 1]
set comment [lindex $argv 2]
spawn ssh root@$IP $comment
expect {
"yes/no"
{send "yse\r";exp_continue}
"password:"
{send "$PASS\r"}
}
interact
标签:脚本编写
原文地址:http://12183531.blog.51cto.com/12173531/1883201