第八周作业
1、用shell脚本实现自动登录机器 #!/usr/bin/expect set usr root set pw 123456 set ip 192.168.0.100 spawn ssh $usr@$ip expect { "yes/no" { send "yes\n";exp_continue } "password" { send "$pw\n" } } interact 2、shell 判断一个值bone是否在数组arrayZ=( one two three four five five )中 #!/bin/bash arrayZ=( one two three four five five bone ) for ((i=0;i<`echo ${arrayZ[*]}`;i++));do if [[`echo ${arrayZ[$i]}` =~ ^bone$ ]];then echo "bone in arrayZ" else echo "bone not in arrayZ" fi done 3、用命令或者脚本实现 0057AF051EFF 变为 00:57:AF:05:1E:FF 。 #!/bin/bash mac=0057AF051EFF for i in `seq 0 2 10`;do if [ $i -eq 10 ];then echo "${mac:$i:2}"