SH 脚本的几个错误,帮忙看下
[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