自动执行交互式工具一(管道或者here文档)

2177阅读 0评论2009-09-14 fucj
分类:LINUX

1、管道方法
#!/bin/sh

F="xxxx.ftp"

echo "open 192.168.7.51 21"     > $F
echo "user username passwd"     >> $F
echo "bin"                      >> $F
echo "cd /home/xxx/"            >> $F
echo "mput $1"                  >> $F
echo "bye"                      >> $F

ftp -i -in < $F
rm -rf $F
 
2、here方法
 
#!/bin/sh
FILE=$1
ftp -i -in <open 192.168.7.9 21
user username password
cd /           
mput $FILE
bye
!
 
 
注:为什么用管道或here文档的方法不能实现自动ssh,su与更改密码?
A:这些程序需要从tty获得输入而不是标准输入,通用的解决办法是expect,请察看“自动执行交互式工具二(expect)”
 
附上windows下的ftp自动登录脚本
echo user anonymous ident >tmp.txt
echo bin >>tmp.txt
echo cd /somedir >>tmp.txt
echo get %1 >>tmp.txt
echo bye >>tmp.txt
ftp -n -s:tmp.txt 192.168.1.5
del tmp.txt
上一篇:fvwm 说明手册笔记
下一篇:find 命令的一些应用