第十二章 Shell脚本编写及常见面试题(三) |
您所在的位置:网站首页 › 奥匈帝国是哪里 › 第十二章 Shell脚本编写及常见面试题(三) |
本章目录: 12.21 FTP下载文件 #!/bin/bash if [ $# -ne 1 ]; then echo "Usage: $0 filename" fi dir=$(dirname $1) file=$(basename $1) ftp -n -v /dev/tcp/$HOST/$PORT; then echo "$PORT open" else echo "$PORT close" fi done12.27 Expect实现SSH免交互执行命令 需要先安装expect工具。 expect涉及用法说明: 命令描述 set可以设置超时,也可以设置变量 timeout超时等待时间,默认10s spawn执行一个命令 expect ""匹配输出的内容 exp_continue继续执行下面匹配 \r回车 $argc统计位置参数数量 [lindex $argv 0]位置参数 puts打印字符串,类似于echo expect{...}输入多行记录 方法1:EOF标准输出作为expect标准输入 #!/bin/bash USER=root PASS=123.com IP=192.168.1.120 expect $NEW_INFO expect -c " spawn ssh -p$PORT $USER@$IP set timeout 2 expect { \"(yes/no)\" {send \"yes\r\";exp_continue} \"password:\" {send \"$PASS\r\";exp_continue} \"$USER@*\" {send \"echo \'$NEW_PASS\' |passwd --stdin $USER\r exit\r\";exp_continue} }" done生成新密码new_info文件: 192.168.18.217 root n8wX3mU% 22 192.168.18.218 root c87;ZnnL 22 12.29 打印乘法口诀 方法1: # awk 'BEGIN{for(n=0;n++ |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |