第六章:随机数和expect
随机数:
1、echo $RANDOM|md5sum 0~32767之间的随机数
2、openssl rand -base64 8
3、date +%s%N
4、head /dev/urandom|cksum
5、cat /proc/sys/kernel/random/uuid
6、echo "sada"|md5sum
创建10个随机字符串组成的文件
#!/bin/bash for i in {1..10} do a=$(openssl rand -base64 40|sed 's/[^a-z]//g'|cut -c 1-10) touch ${a}_nb.html done
expect自动交互命令:
判断多个条件
脚本名:ssh.exp
#!/usr/bin/expect
spawn ssh 192.168.1.1 uptiem
expect
{
send_user "提示信息\n"
"(yes/no)" {exp_send "yes\r";exp_continue} #exp_continue继续匹配的意思
"passwd" {exp_send "123456\r"}
exit {
send_user "程序运行结束"
}
}
expect eof