SH 脚本的几个错误,帮忙看下

踏实每一步 2013-07-19 10:49:08
[root@localhost shared]# ./test.sh
mknod: “in\r”: 不允许的操作
touch: 无法触碰 “out.log\r\r”: 协议错误
: 协议错误 line 17: out.log
: 协议错误 line 18: in
./test.sh: line 19: 8: 错误的文件描述符
: command not found
: command not found
: 协议错误 line 21: in
: command not found
: 协议错误 line 23: in
: command not found
: 协议错误 line 25: in
: command not found
: 协议错误 line 27: in
: command not found
./test.sh: line 32: syntax error in conditional expression
'/test.sh: line 32: syntax error near `]]
'/test.sh: line 32: `if [[ $str = "quit" || $str = "exit" ]]
[root@localhost shared]# tail: 无法打开 “out.log\r” 读取数据: 没有那个文件或目录
tail: no files remaining


下面是运行脚本
#===========autotelnet.sh==============
#!/bin/bash
tmptty='tty'
tmptty='basename $tmptty'
tmpname='whoami'
ip="10.22.33.44"
inp1="ABC^M"
inp2="ABC^M"
inp3="ls^M"
inp4="pwd^M"
inputfile=in
outputfile=out.log
rm -fr $inputfile
rm -fr $outputfile
mknod $inputfile p
touch $outputfile
exec 7<>$outputfile
exec 8<>$inputfile
telnet $ip <&8 >&7&
sleep 2;
echo $inp1 >> $inputfile
sleep 2;
echo $inp2 >> $inputfile
sleep 2;
echo $inp3 >> $inputfile
sleep 2;
echo $inp4 >> $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
ps -ef | grep telnet | grep -v grep | grep -v telnetd | grep $tmptty | grep $tmpname | awk
'{print " kill -9", $2}' | sh
ps -ef | grep tail | grep -v grep | grep -v telnetd | grep $tmptty | grep $tmpname | awk
'{print " kill -9", $2}' | sh
...全文
205 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Carl_CCC 2013-07-19
  • 打赏
  • 举报
回复
你这个脚本应该是windows下编辑的,在linux下格式不对,你使用dos2unix转下格式就应该好了

23,124

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧