1、用shell脚本实现自动登录机器
#!/usr/bin/expect
set ip 192.168.0.112
set user root
set password abc123
set timeout 5
spawn ssh $user@$ip
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$password\n" }
}
interact
运行结果:
2、shell 判断一个值bone是否在数组arrayZ=( one two three four five five )中
#!/bin/bash
declare -a arrayZ
arrayZ=(one two three four five five)
var="bone"
for i in ${arrayZ[*]} ; do
if [ $i == $var ];then
echo $var is in arrayZ.
exit 0
fi
done
echo "$var isn't in arrayZ"
3、用命令或者脚本实现 0057AF051EFF 变为 00:57:AF:05:1E:FF 。
#!/bin/bash
str="0057AF051EFF"
length=${#str}
declare -a arr
echo $str
for(( i=0;i<$