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 .
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?
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 .
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.
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.
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!
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.