xi ti 1
yao qiu: jian ce jiao shi nei suo you kai qi de dian nao,dui yu kai qi de dian nao,xin jian yong hu ,ruo yong hu cun zai bu gai bian qi yuan mi ma
jiao ben:
(1)ssh
[[email protected] useradd]# cat ssh
#!/usr/bin/expect
set timeout 3
set ip [ lindex $argv 0 ]
set passwd [ lindex $argv 1 ]
set comm1 [ lindex $argv 2 ]
set comm2 [ lindex $argv 3 ]
set comm3 [ lindex $argv 4 ]
spawn ssh [email protected]$ip $comm1 $comm2 $comm3
expect {
"yes/no"
{send "yes\r";exp_continue}
"password"
{send "${passwd}\r"}
}
expect eof
(2)ssh1
[[email protected] useradd]# cat ssh1
#!/usr/bin/expect
set timeout 3
set ip [ lindex $argv 0 ]
set passwd [ lindex $argv 1 ]
set comm1 [ lindex $argv 2 ]
set comm2 [ lindex $argv 3 ]
set comm3 [ lindex $argv 4 ]
spawn ssh [email protected]$ip $comm1 $comm2
expect {
"yes/no"
{send "yes\r";exp_continue}
"root"
{send "${passwd}\r";exp_continue}
"New password:"
{send "${comm3}\r";exp_continue}
"Retype new password:"
{send "${comm3}\r"}
}
expect eof
(3)useradd
[[email protected] useradd]# cat useradd
#!/bin/bash
for ((i=226;i<=227;i++))
do
[ -z "$1" -o -z "$2" ] &&
echo "输入电脑密码和要创建的用户" ||
(ping -c1 -w1 172.25.254.$i &>/dev/null &&(
check=`./ssh 172.25.254.$i $1 getent passwd $2 | grep -E "spawn|password" -v`
[ -z ${check} ] &&
(./ssh 172.25.254.$i $1 useradd $2 &>/dev/null;
./ssh1 172.25.254.$i $1 passwd $2 $3 &>/dev/null;
echo success;) ||
echo "$2 exist or passerror") ||
echo down)
done
xi ti 2
dao ji shi
#!/bin/bash
read -p "min:" min
read -p "sec:" sec
read -p "hour:" hour
for ((sec=${sec};sec>=0;sec--))
do
echo -n "倒计时 $hour : $min : $sec "
echo -ne "\r \r"
sleep 1
while [ $sec -le 0 -a $min -gt 0 ] ;do
echo -n "倒计时 $hour : $min : $sec "
echo -ne "\r \r"
((min--))
sec=60
break
done
while [ $hour -gt 0 -a $min -le 0 ] ;do
echo -n "倒计时 $hour : $min : $sec "
echo -ne "\r \r"
((hour--))
min=59
done
done