最近在寫一些簡單的shell script 抄鳥哥的script範例做的如下
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
echo "This program will print your selection !"
# read -p "
[root@Cen5 .bin]# cat testservice.sh
#!/bin/bash
# Program:
# Using netstat and grep to detect WWW,SSH,FTP and Mail services.
# History:
# 2005/08/28 VBird First release
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# 1. echo "Now, I will detect your Linux server's services!"
echo -e "The www, ftp, ssh, and mail will be detect! \n"
test80=$(netstat -tuln | grep ":80")
test22=$(netstat -tuln | grep ':22')
test21=$(netstat -tuln | grep ':21')
test25=$(netstat -tuln | grep ':25')
if [ $test80 != "" ]; then
echo " www service is on "
elif [ $test22 != "" ] ; then
echo " ssh service is on "
elif [ $test21 != "" ] ; then
echo " ftp service is on "
elif [ $test25 != "" ] ; then
echo " mail service is on "
else
echo " no www ssh ftp mail service on"
fi
出現/testservice.sh: line 17: [: too many arguments
./testservice.sh: line 19: [: too many arguments
./testservice.sh: line 21: [: !=: unary operator expected
./testservice.sh: line 23: [: !=: unary operator expected
等錯誤請問這是那裡錯了