Monitoring script issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Monitoring script issue
# 1  
Old 01-06-2011
Data Monitoring script issue

I written following script to monitor two log files. First piece of code working fine, but piece is failing with followin error.

$ sh Log_Monitoring.sh
Database failed to written
4
Database failed to written
expr: syntax error

=================

clear
sh=`date | awk '{print $4}' | cut -d ":" -f1`
sm=`date | awk '{print $4}' | cut -d ":" -f2`
lh=`ls -l /opt/Heartbeat.log | awk '{print $8}' | cut -d ":" -f1`
lm=`ls -l /opt/Heartbeat.log | awk '{print $8}' | cut -d ":" -f2`
if [ x = 0 ]
then
if [ -f "/export/home/paven/interval_core.dat" ]; then
echo "0" > /export/home/paven/interval_core.dat
fi
else
x=`cat /export/home/paven/interval_core.dat`
if [ "$sh" = "$lh" ]
then
if [ "$sm" = "$lm" ]
then
echo "Database writting properly"
echo "0" > /export/home/paven/interval_core.dat
else
echo "Database failed to written"
x=`expr $x + 1`
echo "$x" > /export/home/paven/interval_core.dat
echo $x
if [ "$x" = "2" ]
then
#mailx -s "Data base failed to write in Core Environment - Need to retrieve missing data" -c "xyz@abc.com"<<EOF
echo Data base failed to write in Core Environment - Need to retrieve missing data
fi
fi
fi
fi

sleep 10

sh1=`date | awk '{print $4}' | cut -d ":" -f1`
sm1=`date | awk '{print $4}' | cut -d ":" -f2`
lh1=`ls -l /opt/NH_Heartbeat.log | awk '{print $8}' | cut -d ":" -f1`
lm1=`ls -l /opt/NH_Heartbeat.log | awk '{print $8}' | cut -d ":" -f2`
if [ y = 0 ]
then
if [ -f "/export/home/paven/interval_NH.dat" ]; then
echo "0" > /export/home/paven/interval_NH.dat
fi
else
y=`cat /export/home/paven/interval_NH.dat`
if [ "$sh1" = "$lh1" ]
then
if [ "$sm1" = "$lm1" ]
then
echo "Database writting properly"
echo "0" > /export/home/paven/interval_NH.dat
else
echo "Database failed to written"
y=`expr $y + 1`
echo "$y" > /export/home/paven/interval_NH.dat
echo $y
if [ "$y" = "2" ]
then
#mailx -s "Data base failed to write in NHS Environment - Need to retrieve missing data" -c "xyz@abc.com"<<EOF
echo Data base failed to write - Need to retrieve missing data
fi
fi
fi
fi
================Smilie
# 2  
Old 01-06-2011
The syntax error is becuse there is nothing in $x or $y at the time the respective expr statements are issued.

Without trying to understand the logic of your script, the dubious lines are:
Quote:
if [ x = 0 ]
x=`expr $x + 1`

if [ y = 0 ]
y=`expr $y + 1`
You may find that this helps:
Code:
# Near top of script to fix the later "expr" lines.
x=0
y=0
# Numeric comparisions with $x and $y.
if [ $x -eq 0 ]

if [ $y -eq 0 ]

# 3  
Old 01-06-2011
Variables passed to expr (x or y) are not initialized.
You are assigning values to x or y in if/else block, so depending on conditions, x/y may not be initialized.
Pls make sure you initilize x and y out of if/else bolck.
Have a look at your earlier post:
https://www.unix.com/shell-programmin...t-working.html

Last edited by anurag.singh; 01-06-2011 at 10:12 AM..
This User Gave Thanks to anurag.singh For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Website RTO. What monitoring can I setup and how to track issue?

Hello, I have installed a WordPress theme on Cantos and brought up a website on AWS. I have added that website on Cloudflare. While I was working on webpage development, I noticed that sometimes website is unreachable. In 8 hours, I noticed it 2-3 times and after few seconds, it would come back... (1 Reply)
Discussion started by: solaris_1977
1 Replies

2. Linux

Check_esx_host_vmfs plugin issue while monitoring ESXi DS

Hello, I setup a check_esx_host_vmfs plugin for monitoring datastore status on ESXi server. But on configuring this plugin, this is working fine but it displays "WARNING" status on UI of Nagios every time. Currently my datastore size is 926.50 GB and right now free space available is 570.60 GB... (2 Replies)
Discussion started by: sunnysthakur
2 Replies

3. Shell Programming and Scripting

Help with a monitoring script

I currently have a shellscript to check the size of a filesystem and email me if the size is over a certain percentage (80%). I have this script on crontab and executes the shell every 10 mins. I have the above in place on 8 servers. It so happens that a file system on one of the servers is... (1 Reply)
Discussion started by: goddevil
1 Replies

4. UNIX for Advanced & Expert Users

ldapsearch in monitoring script without bind password written in script

Hi I do a very simple monitoring of our OpenLDAP (runs in cronjob and generate alerts if unsuccessfull) $ ldapsearch -h hostname.domain -D "cn=monitor_user,ou=People,dc=organisation" -w "password" -b "dc=organisation" -x "(&(cn=monitor_user)(ou=People))" dn | grep -v version dn:... (4 Replies)
Discussion started by: slashdotweenie
4 Replies

5. Solaris

Monitoring issue

can any one help me in this issue iscsiadm: ISCSI_AUTH_GET failed, errno: 5 Monitored File: /var/adm/messages (1 Reply)
Discussion started by: saripudi1985
1 Replies

6. Red Hat

monitoring script

Hi, I ned to monitor the memory for the red-hat machine,when its reaches a threshold value like 2GB then a mail should be sent as soon as it finds the the value is met can you suggest me which is the best way to do this? (2 Replies)
Discussion started by: sriniv666
2 Replies

7. Shell Programming and Scripting

Snmp Process Monitoring Issue

Can someone please explain to me how come snmpwalk doesn't always find a running process that's on a remote server? I prefer to use snmp to monitor processes remotely because this doesn't require me to put a script on that remote box. but the problem is, there are times that my snmp command... (2 Replies)
Discussion started by: SkySmart
2 Replies

8. Shell Programming and Scripting

Help with Monitoring script

Hi Gurus, Currently I am learning UNIX through online forums and unix blogs. I have the below requirement. I need to write a script to monitor server processes. For example, there are 3 processes currently running on the server.(java, pmrepagent, pmserver). If any of the process goes down,... (2 Replies)
Discussion started by: svajhala
2 Replies

9. UNIX for Advanced & Expert Users

monitoring script

i have a unix batch written in c, dealing with really time-consuming database operations i want to write a ksh script to monitor its performance. which items i should monitor? do you have any suggestions? 1)cputime 2)swap area 3)pmem 4) 5) what else? (1 Reply)
Discussion started by: gfhgfnhhn
1 Replies

10. UNIX for Dummies Questions & Answers

monitoring script

hi can someone help me to write a script to monitor the growth of the directory running at 5 hours interval and then pipe it to a file :(? i only know the manual command "du -sk" and the worst i dun know anything about script. (3 Replies)
Discussion started by: legato
3 Replies
Login or Register to Ask a Question