Linux脚本

1、用shell脚本实现自动登录机器

 1     #!/usr/bin/expect 
 2     set ip 192.168.8.100 
 3     set user root 
 4     set password magedu 
 5     set timeout 10 
 6     spawn ssh $user@$ip 
 7     expect { 
 8             "yes/no" { send "yes\n";exp_continue } 
 9             "password" { send "$password\n" } 
10     } 
11     interact 

2.shell 判断一个值bone是否在数组arrayZ=( one two three four five five )中

 1 #/bin/bash
 2 declare -a arrayZ
 3 arrayZ=( one two three four five five )
 4 for i in `seq 0 $[${#arrayZ[@]}-1]`;do
 5         echo ${arrayZ[$i]}
 6     if [ ${arrayZ[$i] == bone ];then
 7         echo "yes,${arrayZ[$i]} exits"
 8     else
 9         echo "${arrayZ[$i]} not is bone"
10 
11     fi
12 done
13 unset arrayZ

3.用命令或者脚本实现 0057AF051EFF 变为 00:57:AF:05:1E:FF

1 #/bin/bash
2 var=0057AF051EFF
3 echo ${var:0:2}:${var:2:2}:${var:4:2}:${var:6:2}:${var:8:2}:${var:10:2}
4 unset var

4.a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9 0 \! \@ \# \$ \% \^ \& \* \( \) \- \_ \= \+ \\ \/ \' \" \; \: \[ \] \{ \} \, \. \?用以上字符,结合数组,实现一个随机生成20位密码的脚本

 1 #!/bin/bash
 2 array=(`echo {0..9}` `echo {a..z}` `echo {A..Z}` \! \@ \# \$ \% \^ \& \_ \- \+ \= \{ \} \[ \] \" \' \:
 3  \; \? \\ \/ \. \> \, \<)
 4 for i in `seq 0 19`;do
 5     num=$RANDOM%89
 6     if  [ $i -lt 20 ];then
 7             echo -n ${array[$num]}
 8     fi
 9 done
10 echo
11 unset array

 

你可能感兴趣的:(Linux脚本)