Sponsored Content
Top Forums Shell Programming and Scripting Error in script to automate the daily monitoring process of UNIX server and it's proc Post 302308940 by cfajohnson on Monday 20th of April 2009 04:47:18 PM
Old 04-20-2009
Quote:
Originally Posted by rdhaprakasam
thanks guru the problem was resolved .
but i got syntax error at error while executing . please help me friends,

Please put code inside [code] 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.
Quote:
Code:
 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`


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

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

Quote:
Code:
 7  if [ $NOF -ne 0 ]
 8  then
 9          NOF=`expr $NOF - 1`


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

Code:
NOF=$(( $NOF - 1 ))

(But you don't need it if you don't use ls | wc.)
Quote:
Code:
10  fi
11
12  OUTFILE="/root/temp/checking/outputfile"


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

That's asking for trouble.
Quote:
Code:
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;


There is only one value in $FILE, so why are you using a loop?
Quote:
Code:
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


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

Code:
{
  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

Quote:
Code:
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;


Why are you using a for loop for a single value?
Quote:
Code:
60  do
61  temp=`ls -lt /root/COMM/LOGS/eds/20081215 | tr -s " " | cut -f6,7,8,9 -d " " `"


Remove the double quotes from the end of the line; that's what's causing the error; it is unmatched.
Quote:
Code:
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
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automate daily FTP files

How to automate FTP files daily with the following constraints 1) Try (every 15 mins or 30 mins) FTP till it reconnects 2) Files that arrive in between 5:30 pm and 2:00 am 3) The sat and sun, mon files are to be FTP on monday. 4) Only the txt files are to be FTP'ed. The following are the... (2 Replies)
Discussion started by: bobbygsk
2 Replies

2. Shell Programming and Scripting

Automate Log Monitoring Process

I am a new member of this forum and am also new to unix shell scripting. I joined the forum to seek for help to achieve my task as this forum helps people. here's what i do manually on daily basis 1)Loginto different unix box 2)Ftp the log files (morethan 50 each dir) to windows 3)use text pad... (3 Replies)
Discussion started by: sharugan
3 Replies

3. Shell Programming and Scripting

automating daily monitoring process

Hi there, I have to automate daily monitoring process and then the result of these process should be sent to a log file, then this log file should be mailed . ps -ef | grep aa In this atleast one process should run. If the process is running it should mention Success in the log file... (3 Replies)
Discussion started by: NehaKrish
3 Replies

4. Shell Programming and Scripting

Bash script to Automate the Virtual Host creation process!!

Hi all, This is my sample code in /etc/httpd/conf.d/applications.conf file currently we are creating subdomain mannually for every new subdomain. I want to automate this process througs bash script , how its possible. <VirtualHost *:80> ServerName google.com ServerAlias google.com... (5 Replies)
Discussion started by: anishkumarv
5 Replies

5. Shell Programming and Scripting

Need help in creating a shell script to automate svnstats process

Hi, I am trying to create a shell script to automate the following process of getting svn stats:- Step1:- cd to checkout location. Note that the checked code have multiple modules in respective folders Step2:- Execute this command inside each module:- svn log -v --xml >... (0 Replies)
Discussion started by: d8011
0 Replies

6. UNIX for Dummies Questions & Answers

Automate sftp process using script

Hi, guys, I am trying to automate a sftp process using "expect" method (since the key authentication method is disabled in my company network, there is no helping it). In order to try, I type in the command manually: sftp @ > << EOF >cd >ls -l >EOF >Connecting to @servername password: ... (3 Replies)
Discussion started by: warmboy610
3 Replies

7. Shell Programming and Scripting

Help me with daily monitoring script

find /usr/IBM/FileNet/BulkUploaderScript/$i/Log/SuccessLog \( -newer range_start -a \! -newer range_end \) -exec wc -l {} \; |awk '{total+=$1-1} END {print total}' >>$LOGFILE I need to print time stamp of the files int the paticular period .Please modify the above script so that i get... (34 Replies)
Discussion started by: RaghavendraT
34 Replies

8. Emergency UNIX and Linux Support

Monitoring progress of a process in Linux server

Hi friends, I am quite used to using glance in HPUX servers for analysis performance issues with a particular process as requested by app. folks. The options which are very helpful to me are the "F" , "W" , "L" stats. How can i get the similar details on Linux servers without using glance?... (2 Replies)
Discussion started by: kunwar
2 Replies

9. Shell Programming and Scripting

Script to automate recovery process

Hello All! First post... I am working on a script that is used to recover a crashed drive from an rsync backup. I'm down to the place where I need to create all of the directories in /mnt where I will then mount each of the volumes and begin the restore process to each volume... I have... (3 Replies)
Discussion started by: RogerBaran
3 Replies

10. Open Source

Help with writing Shell Script to automate process using multiple commands

Hello! Need help to write a Linux script that can be run from windows using command/Cygwin/any other way. I am new to scripting, actually i am trying to automate server health check like free disk space, memory along with few services status, if any services is not running then start services ,... (7 Replies)
Discussion started by: Sayed Ibrahim
7 Replies
All times are GMT -4. The time now is 07:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy