LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 972|回复: 11

找不出程序错的地方,请帮忙??

[复制链接]
发表于 2004-3-3 14:37:27 | 显示全部楼层 |阅读模式
[root@monitor monitor_script]# ./alert_ping.sh
: command not foundne 6:
: command not foundne 17:
'/alert_ping.sh: line 18: syntax error near unexpected token `
'/alert_ping.sh: line 18: `mail_body()

*************************[code]**********************************

# !/bin/sh
# Scriptname: Alert Ping
# Purpose: Ping all the local server for monitor
# Writed by: ^.^
# Script start ...

# Define
counter=0
hostname=`hostname`
script_path=/home/monitor_script/
log_path=$script_path/log
mail_path=$script_path/sendmail_header
music_path=$script_path/danger.au
mail_list=$script_path/maillist
ip_list=$script_path/iplist
ErrTime=`date +%Y/%m/%d/%H:%M:%S`

mail_body()
{
        addressee=$1
        mail_file=$2
        echo "From: Monitor_Pc_NP@server" > $mail_path
        echo "To: $addressee" >> $mail_path
        echo "Subject: Server Ping Report from $ipaddress" >> $mail_path
        echo "Content-Type: html; charset=big5;"  >> $mail_path
        echo "" >> $mail_path
        echo "$ErrTime" >> $mail_path
        echo "" >> $mail_path
        echo "$hostname"  "$ipaddress"  "Can not be connected" >> $mail_path
        echo "" >> $mail_path
        echo "Monitor System run times: $counter" >> $mail_path
        echo "" >> $mail_path
        echo $mail_file
        sendmail $addressee < $mail_path
}

sned_mail()
{
        mail_list=$1
        mail_file=$2
        while read line
        do
                mail_body $line $mail_file
        done
}

counter=`expr $counter + 1`
echo "Counter: $counter"
echo "Monitor begin."
cat $ip_list | grep -v '^#' | awk '{ print $1 }' | while read ipaddress
do
ping -c 1 -w 5 $ipaddress 1>/dev/null 2>&1
if [ $? -ne 0 ]
then
send_mail $mail_list
#play -v 50 -p $music_path >/dev/null 2>&1
echo $ipaddress "Can not be connected"
echo "$ErrTime""  ""$hostname""  ""$ipaddress"" Can not be connected" >> $log_path
else
echo $ipaddress "is alive."
fi
done
echo "The end."
发表于 2004-3-3 15:09:19 | 显示全部楼层
**script_path=/home/monitor_script/
* log_path=$script_path/log
* mail_path=$script_path/sendmail_header
* music_path=$script_path/danger.au
* mail_list=$script_path/maillist
* ip_list=$script_path/iplist
上述这些变量的赋值换成
*ip_list=${script_path}iplist这样的形式

**script_path="/home/monitor_script/"
 楼主| 发表于 2004-3-3 15:15:05 | 显示全部楼层
to:javalee
改了,错误依旧还有呀~~
 楼主| 发表于 2004-3-3 15:17:42 | 显示全部楼层
老提示我在main_body中语法错了
发表于 2004-3-3 15:25:11 | 显示全部楼层
sh -xv alert
看看错误具体出自哪里?
 楼主| 发表于 2004-3-3 15:50:37 | 显示全部楼层

不会看呀~~

[root@monitor monitor_script]# sh -xv alert_ping.sh
# !/bin/sh
# Scriptname: Alert Ping
# Purpose: Ping all the local server for monitor
# Writed by: ^.^
# Script start ...

+ $'\r'
: command not found 6:
# Define
counter=0
+ counter=0
hostname=`hostname`
hostname
++ hostname
+ hostname=monitor
script_path="/home/monitor_script/"
+ script_path=/home/monitor_script/
log_path="${script_path}/log"
/logg_path=/home/monitor_script/
mail_path="${script_path}/sendmail_header"
/sendmail_headere/monitor_script/
music_path="${script_path}/danger.au"
/danger.auth=/home/monitor_script/
mail_list="${script_path}/maillist"
/maillistst=/home/monitor_script/
ip_list="${script_path}/iplist"
/iplistst=/home/monitor_script/
ErrTime=`date +%Y/%m/%d/%H:%M:%S`
date +%Y/%m/%d/%H:%M:%S
++ date +%Y/%m/%d/%H:%M:%S
+ ErrTime=2004/03/03/15:36:32

+ $'\r'
: command not found 17:
mail_body()
'lert_ping.sh: line 18: syntax error near unexpected token `
'lert_ping.sh: line 18: `mail_body()
 楼主| 发表于 2004-3-3 15:52:36 | 显示全部楼层
找到一个错误了,原来注释和程序之间是不能有空行的,唉~~~
发表于 2004-3-3 16:12:26 | 显示全部楼层
定义的函数名字出现错写!
error 1:sned_mail()
error 2:send_mail $mail_list
发表于 2004-3-3 18:17:20 | 显示全部楼层
最初由 puzzie 发表
找到一个错误了,原来注释和程序之间是不能有空行的,唉~~~

不懂
发表于 2004-3-3 23:19:17 | 显示全部楼层
最初由 puzzie 发表
找到一个错误了,原来注释和程序之间是不能有空行的,唉~~~

老兄的脚本大概是在dos or windows环境下录入的吧?
dos的换行符为\r\n,shell环境下会出错。
在论坛搜一下如何转换dos格式的文章,或者用vi手工录入一遍^_^
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表