Error in script to automate the daily monitoring process of UNIX server and it's proc

hi friends,
I am trying to automate the daily monitoring process of UNIX server and it's processes. the script are below

             i executed the above script using ksh -x monitortest1.sh in root login . It shows error at some lines .
  1. i logged in using root ,but it shows below directory is not found . i never mentioned the below line anywhere in the script .
    /prakash/COMM/LOGS/eds/20081025: not found
    i don't know why it comes?

  2. at script file line no 61
    temp = `ls -lt /root/COMM/LOGS/eds/20081215 | tr -s " " | cut -f6,7,8,9 -d " " `

monitortest1.sh[60]: temp: cannot execute
+ /root/COMM/LOGS/eds/20081215
monitortest1.sh[61]: /root/COMM/LOGS/eds/20081215: cannot execute
but it runs fine if i alone in shell .

3.At line 83 i wrote like bvelow . but it shows error .
echo -e "\n\n `ls -lt /root/COMM/LOGS/eds/20081215 | tr -s " " | cut -f6,7,8,9 -d " " `" >> $MFILE
4.error on below lines
echo "test i prakash" $j
echo "test temp prakash" $temp

i have attached both script file and out put file can anyone help me out ?
Thanks in advance .

Please put code inside [code] tags.

Please attach scripts, not MSWord documents. Better still, put the script in the post.

As cfajohnson states, please post the script in "code" tags.
Space characters are very important to this problem.

Your issue on line 60 for example is easier to see in an even font.
The spaces either side of the equals sign cause the error:

temp = `ls -lt /root/COMM/LOGS/eds/20081215 | tr -s " " | cut -f6,7,8,9 -d " " `
Should be:
temp=`ls -lt /root/COMM/LOGS/eds/20081215 | tr -s " " | cut -f6,7,8,9 -d " " `

Line 12 similarly, the space after the equals sign.

OUTFILE= /root/temp/checking/outputfile
Should be:
OUTFILE="/root/temp/checking/outputfile"

Please post the output from the following command:
The -ltb is to show funny characters in filenames.
I suspect that you have a filename with a unix command in it!

ls -ltb /root/COMM/LOGS/eds/20081215

There are other quirks in the script, but first please go through every variable
assignment and check that there are no spaces either side of an equals sign.

BTW. I don't think this is valid in ksh:

echo -e

thanks guru i will check it and get back you soon

thanks guru the problem was resolved .
but i got syntax error at error while executing . please help me friends,
1 #!/bin/ksh
2 ##
3 ##### To find no of files in the directory
4
5
6 NOF=`ls -l /root/COMM/LOGS/eds/20081025| wc -l`
7 if [ $NOF -ne 0 ]
8 then
9 NOF=`expr $NOF - 1`
10 fi
11
12 OUTFILE="/root/temp/checking/outputfile"
13 #OUTFILE= /root/temp/checking/outputfile
14 FILE=`cat /root/temp/checking/address.txt | wc -l`
15
16 echo " /root/COMM/LOGS/eds/20081025 no of files is ${NOF} " > $OUTFILE
17
18
19 if [ $NOF -ne 0 ]
20 then
21
22 for i in $FILE;
23 do
24 TO=`head -$i /root/temp/checking/address.txt | tail -1`
25
26 MFILE=/root/temp/checking/mailfile
27
28 echo "From: "Gnanaprakasam" <gnanaprakasam@yahoo.com>" > $MFILE
29 echo "To: ${TO}" >> $MFILE
30 echo "Date: `date`" >> $MFILE
31 echo "Subject: due to the script execution problem " >> $MFILE
32 echo "\n\n" >> $MFILE
33 echo "Dear Sir/Madam," >> $MFILE
34 echo "\n\t Due to the script execution problem the following file are created" >> $MFILE
35 echo "\n\n `ls -lt /root/COMM/LOGS/eds/20081025 | tr -s " " | cut -f6,7,8,9 -d " " `" >> $MFILE
36 echo "\n" >> $MFILE
37
38 ##/bin/cat $MFILE | /usr/sbin/sendmail -fgnanaprakasam@yahoo.com $TO
39 sleep 2
40 done
41
42 fi
43
44
45
46
47
48 NOF1=`ls -l /root/COMM/LOGS/eds/20081215 | wc -l`
49 if [ $NOF1 -ne 0 ]
50 then
51 NOF1=`expr $NOF1 - 1`
52 fi
53
54 echo text >> $OUTFILE
55 DIRFILE=/root/COMM/LOGS/eds/20081215
56 echo "/root/COMM/LOGS/eds/20081215 no of files is ${NOF1} " >> $OUTFILE
57 if [ $NOF1 -ne 0 ]
58 then
59 for j in $DIRFILE;
60 do
61 temp=`ls -lt /root/COMM/LOGS/eds/20081215 | tr -s " " | cut -f6,7,8,9 -d " " `"
62 echo "test j prakash" $j
63 echo "test temp prakash" $temp
64 echo "test DIRFILE" $DIRFILE
65 done
66 for i in $FILE;
67 do
68 echo test start
69 echo "test i prakash"$i
70 echo test stop
71 TO=`head -$i /root/temp/checking/address.txt | tail -1`
72
73 MFILE="/root/temp/checking/mailfile"
74 TEST=`ls -lt /root/COMM/LOGS/eds/20081215`
75
76 echo "From: "Gnanaprakasam" <gnanaprakasam@yahoo.com>" > $MFILE
77 echo "To: ${TO}" >> $MFILE
78 echo "From: "Gnanaprakasam" <gnanaprakasam@yahoo.com>" > $MFILE
79 echo "To: ${TO}" >> $MFILE
80 echo "Date: `date`" >> $MFILE
81 echo "Subject: due to the script execution problem " >> $MFILE
82 echo "\n\n" >> $MFILE
83 echo "Dear Sir/Madam," >> $MFILE
84 echo "\n\t Due to the script execution problem the following file are created" >> $MFILE
85 echo "\n\n `ls -lt /root/COMM/LOGS/eds/20081215 | tr -s " " | cut -f6,7,8,9 -d " " `" >> $MFILE
86 echo "\n" >> $MFILE
87
88 #/bin/cat $MFILE | /usr/sbin/sendmail -fgnanaprakasam@yahoo.com $TO
89 sleep 2
90 done
91 fi

+ 1>> /root/temp/checking/outputfile
monitortest1.sh[56]: syntax error at line 86 : `"' unmatched

i have checked .there is no white space

Am using HP-UX and ksh shell

Are you sure you have a 'done' for every 'do' while? Where does #23 do end?

Please put code inside

 tags.

And please post real code that can be selected and copied to a file; if you want to put in line numbers, please do it in comments at the end of the line.


 1  #!/bin/ksh
 2  ##
 3  ##### To find no of files in the directory
 4
 5
 6  NOF=`ls -l /root/COMM/LOGS/eds/20081025| wc -l`

[/quote]

[indent]
There's no need to use external commands to get the number of files in a directory:

set -f
set --   /root/COMM/LOGS/eds/20081025/*
NOF=$#

You are using ksh; why are you using an external command for arithmetic?

NOF=$(( $NOF - 1 ))

(But you don't need it if you don't use ls | wc.)

Are you really running buggy code as root????

That's asking for trouble.

There is only one value in $FILE, so why are you using a loop?

Group your commands (here and elsewhere) and use a single redirection:

{
  echo "From: "Gnanaprakasam" <gnanaprakasam@yahoo.com>"
  echo "To: ${TO}"
  echo "Date: `date`"
  echo "Subject: due to the script execution problem "
  echo "\n\n"
  echo "Dear Sir/Madam,"
  echo "\n\t Due to the script execution problem the following file are created"
  echo "\n\n `ls -lt /root/COMM/LOGS/eds/20081025 | tr -s " " | cut -f6,7,8,9 -d " " `"
  echo "\n"
} > $MFILE

Why are you using a for loop for a single value?

Remove the double quotes from the end of the line; that's what's causing the error; it is unmatched.

All I have to say here is that this is the result of a bad coding practice. Indentation helps.

Moreover, experts have repeatedly requested the use of

 tag.


if [ I write code like this ];then
    Ppl can help me better
else
    I'll waste a lot of effort and time
fi

The error message means that you have an uneven number of one type of quotes. These could be single quotes, double quotes, or back ticks.

This line for example is suspect. Though the backticks are matched, there are 5 double quote characters. The double quote at the end of the line will cause a syntax error. On re-reading cfajohnson's post I see that he spotted this too and queried the logic!

61 temp=`ls -lt /root/COMM/LOGS/eds/20081215 | tr -s " " | cut -f6,7,8,9 -d " " `"

This line does not have a syntax problem as such, but does have too many double quotes to be easy to read by eye.

28 echo "From: "Gnanaprakasam" <gnanaprakasam@yahoo.com>" > $MFILE

28 echo "From: Gnanaprakasam <gnanaprakasam@yahoo.com>" > $MFILE

cfajohnson makes a very good point about using one redirection to $MFILE. It would make the script so much easier to follow. Similarly testing a buggy script as root is not advisible.