[问题]求助,能不能让shell脚本向程序输入多行命令参数?
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
- Nile
- 帖子: 990
- 注册时间: 2006-07-15 11:20
- 来自: 枫叶刀市
[问题]求助,能不能让shell脚本向程序输入多行命令参数?
有些命令参数无法一行输完,比如瑞捷的xrgsu,需要按回车才能输入下一个参数,能不能用一个shell脚本一次性把这些参数都输完?
谢谢每一个回帖的朋友!
谢谢每一个回帖的朋友!
Thinkpad T400
- Nile
- 帖子: 990
- 注册时间: 2006-07-15 11:20
- 来自: 枫叶刀市
- Nile
- 帖子: 990
- 注册时间: 2006-07-15 11:20
- 来自: 枫叶刀市
-
- 帖子: 262
- 注册时间: 2007-03-29 12:59
- Nile
- 帖子: 990
- 注册时间: 2006-07-15 11:20
- 来自: 枫叶刀市
先谢谢楼上的。
理论上应该没错,可以把参数分别传给程序,但我研究了半天,总感觉在参数前好像多传了一个回车之类的东西,理由是xrgsu得到的参数好像都后措了一位!因为没法看到具体参数所以只是推测(也有可能根本没传进去)。
但可以试试
没有任何反应!
再试试
打开的文件是“未命名”!
aa并没有传给gvim,奇怪!
我又试了一下文件输入重定向的方法,
新建一个文本aa.sh
再输入
新建的文件名还是“未命名”!
求高人指教!
理论上应该没错,可以把参数分别传给程序,但我研究了半天,总感觉在参数前好像多传了一个回车之类的东西,理由是xrgsu得到的参数好像都后措了一位!因为没法看到具体参数所以只是推测(也有可能根本没传进去)。
但可以试试
代码: 全选
echo -e "/home"| cd
再试试
代码: 全选
sudo echo -e "aa" | gvim
aa并没有传给gvim,奇怪!
我又试了一下文件输入重定向的方法,
新建一个文本aa.sh
代码: 全选
aa
代码: 全选
gvim < aa.sh
求高人指教!
Thinkpad T400
- Nile
- 帖子: 990
- 注册时间: 2006-07-15 11:20
- 来自: 枫叶刀市
-
- 帖子: 262
- 注册时间: 2007-03-29 12:59
这里有一个自动输入用户名和密码的telnet shell 或许对你有帮助
原载chinaunix.net shell版 作者panlm
发表于: 2003-11-13 10:00
自动输入用户名和密码用于tenlnet的shell, 哈哈
用linux的朋友且经常用配置路由器的可有福了.
今天刚刚完成, 大家多提意见
#===========autotelnet.sh==============
#!/bin/bash
if (( $# != 1 ))
then
echo " usage: $0 address "
exit 1
fi
ip=$1
inp1=`cat param |grep "$ip" |awk '{ print $2 }'`
inp2=`cat param |grep "$ip" |awk '{ print $3 }'`
inp3=`cat param |grep "$ip" |awk '{ print $4 }'`
inputfile=in
outputfile=out
rm -fr $inputfile
rm -fr $outputfile
mknod $inputfile p
touch $outputfile
#file description 7 for out and 8 for in
exec 7<>$outputfile
exec 8<>$inputfile
telnet $ip <&8 >&7 &
sleep 1; echo $inp1 >> $inputfile
sleep 1; echo $inp2 >> $inputfile
sleep 1; echo $inp3 >> $inputfile
tail -f $outputfile &
while true
do
read str
if [[ $str = "quit" || $str = "exit" ]]
then echo $str >> $inputfile ; exit
else echo $str >> $inputfile
fi
done
#==================================
参数文件, 输入在出现正常提示符之前需要输入的所有内容, 用空格分开, 以ip地址或者hostname开头
#=====param============
localhost root password
#=====================
原载chinaunix.net shell版 作者panlm
发表于: 2003-11-13 10:00
自动输入用户名和密码用于tenlnet的shell, 哈哈
用linux的朋友且经常用配置路由器的可有福了.
今天刚刚完成, 大家多提意见
#===========autotelnet.sh==============
#!/bin/bash
if (( $# != 1 ))
then
echo " usage: $0 address "
exit 1
fi
ip=$1
inp1=`cat param |grep "$ip" |awk '{ print $2 }'`
inp2=`cat param |grep "$ip" |awk '{ print $3 }'`
inp3=`cat param |grep "$ip" |awk '{ print $4 }'`
inputfile=in
outputfile=out
rm -fr $inputfile
rm -fr $outputfile
mknod $inputfile p
touch $outputfile
#file description 7 for out and 8 for in
exec 7<>$outputfile
exec 8<>$inputfile
telnet $ip <&8 >&7 &
sleep 1; echo $inp1 >> $inputfile
sleep 1; echo $inp2 >> $inputfile
sleep 1; echo $inp3 >> $inputfile
tail -f $outputfile &
while true
do
read str
if [[ $str = "quit" || $str = "exit" ]]
then echo $str >> $inputfile ; exit
else echo $str >> $inputfile
fi
done
#==================================
参数文件, 输入在出现正常提示符之前需要输入的所有内容, 用空格分开, 以ip地址或者hostname开头
#=====param============
localhost root password
#=====================