Script Help - Another Way To Write This


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script Help - Another Way To Write This
# 1  
Old 04-16-2009
Script Help - Another Way To Write This

I am adapting an Open Step ping server script to Ubuntu 8.10 and one section of my script isn't working

Code:
# if there are servers that just went down or came back up, notify
# with high importance
if [ -s /tmp/$SCRIPTNAME.serverlist.upagain -o -s /tmp/$SCRIPTNAME.serverlist.wentdown ]; then
echo notifying of servers that are up again or just now down
notify high
# if there is no new news, but servers are still down from before,
# notify only once per day, with low importance
elif [ -s /tmp/$SCRIPTNAME.serverlist.stilldown ]; then
if [ "`date +%H`" -eq 11 ]; then
if [ ! -f /tmp/$SCRIPTNAME.stilldownsent ]; then
touch /tmp/$SCRIPTNAME.stilldownsent
echo notifying once today of servers that are still down from before
notify low
fi
else
echo not time for daily notification of servers that are still down
if [ -f /tmp/$SCRIPTNAME.stilldownsent ]; then
rm /tmp/$SCRIPTNAME.stilldownsent
fi
fi



The first if statement
Code:
if [ -s /tmp/$SCRIPTNAME.serverlist.upagain -o -s /tmp/$SCRIPTNAME.serverlist.wentdown ]; then
echo notifying of servers that are up again or just now down
notify high


isn't being executed and notifying/emailing me of the updates when a server comes back up. When a server goes down, its fine, but if that server comes back up, it won't notify me until something new goes down. Is this "if" statement not Ubuntu friendly or is there another way to write it. The jest of the "if" statement there is if file1 or file2 are more than 0 bytes run notify

Here is the notify section if that would be helpful
Code:
# function to send the email notification with high or low importance
notify()
{
echo "
This message sent by cron script /admin/scripts/crons/ping_servers.sh on 
mjm101" > /tmp/$SCRIPTNAME.serverlist.explain
cat /tmp/$SCRIPTNAME.serverlist.upagain /tmp/$SCRIPTNAME.serverlist.wentdown /
tmp/$SCRIPTNAME.serverlist.stilldown /tmp/$SCRIPTNAME.serverlist.explain | /usr/
bin/sendEmail -f mjm102@blink.com -t stan.smith@blink.com -u "RCP Server Stats" -s abcd.edc.mail.net
cat /tmp/$SCRIPTNAME.serverlist.upagain /tmp/$SCRIPTNAME.serverlist.wentdown |
logger -t "ping_servers.sh" -p local4.err
}



Any help appreciated. I can not see why it won't run the notify section unless its some syntax on the first "if" statement. Thanks! Dale

Last edited by gbxfan; 04-16-2009 at 08:44 PM..
# 2  
Old 04-17-2009
Try one of these if statements, they should work with bash:

Code:
if [[ -s /tmp/$SCRIPTNAME.serverlist.upagain || -s /tmp/$SCRIPTNAME.serverlist.wentdown ]]; then

Code:
if [ -s /tmp/$SCRIPTNAME.serverlist.upagain ] || [ -s /tmp/$SCRIPTNAME.serverlist.wentdown ]; then

Regards
# 3  
Old 04-17-2009
Thank you Franklin52 - I am good - Thank you so much. Dale
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Please help me to write the script

Hi All, I have written the follwing script to take the backup of the file every day along with the date. DATE=`date +%Y%m%d` export DATE cp var/hr/hr333m.txt cp var/hr/payments/hr333m_$DATE.txt The file name as follows after taking the backup. hr333m_20110630.txt Could you... (3 Replies)
Discussion started by: ajaykumarkona
3 Replies

2. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

3. Shell Programming and Scripting

Q: How to write this script?

Hi there :rolleyes: I have a folder called backup it is path is: ~/backup Inside this folder, there are four files: ~/backup/test1.cpp ~/backup/test2.cpp ~/backup/test3.cpp ~/backup/PATHS.TXT The fourth file PATHS.TXT contains the original paths for the three files. This is the... (4 Replies)
Discussion started by: domain
4 Replies

4. AIX

how to write this script?

If I need delete some disk, for i in hdisk1 hdisk2 hdisk3 hdisk4 do rmdev -dl $i done if I have more than 100 hdisks, how to write a script like that to delete them? (6 Replies)
Discussion started by: rainbow_bean
6 Replies

5. Shell Programming and Scripting

Better way to write this script

Hi All, I have written the following script. I have just repeated some commands, and I am sure there is a more better way to do it. I hope I one of gurus here will help me make it in a better shape. Here is the script: #! /bin/sh sed -i -e "s/test2.xxx/test3.xxx/" -e "s/output2/output3/"... (2 Replies)
Discussion started by: faizlo
2 Replies

6. UNIX for Dummies Questions & Answers

Should I write a PERL Script or Shell Script?

Hello, I have done some BASIC shell scripting/PERL scripting before so I am familiar with the languages. I am not really sure which one would lend itself better to the application I have to write. I am required to scan the message logs for possible break in attempts. If I use shell scripting... (2 Replies)
Discussion started by: mojoman
2 Replies

7. Shell Programming and Scripting

Please write this script for me

UNIX shell script (Bourne shell syntax) called admin_script. This script is described below as a usage summary: admin_script Note: if no options are specified, a menu is displayed which allows users to perform one of the following tasks and then exit. If incorrect options are provided,... (1 Reply)
Discussion started by: nadman123
1 Replies

8. Shell Programming and Scripting

Help me to write the script

Actually i am working with two diffrent files having same structure each file contain Ten diffrent column and i want to write a script which will compare the colummns of first file with the column of second file and diiference will be send to the first column of third file . similarly for... (5 Replies)
Discussion started by: gyana_cboy
5 Replies

9. AIX

How to write script for this ?

Hi All, I want to read username and lastupdate only from /etc/security/passwd and write the same data to another file: The data in /etc/security/passwd will be in this form for example: For more details : http://www.unet.univie.ac.at/aix/files/aixfiles/passwd_security.htm#A1219924 smith:... (0 Replies)
Discussion started by: me_haroon
0 Replies

10. Shell Programming and Scripting

Help! Need to write my first script

Hi Folks! I am a MacUser and am trying to learn Unix for the last few months. I will explain in detail what I am trying to do, and apreciate you help if you can teach me even if it is a single comand line inside the script. I own a small company, where I manufacture special gypsums and... (5 Replies)
Discussion started by: fundidor
5 Replies
Login or Register to Ask a Question