Script Conversion To Ubuntu 8.10


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script Conversion To Ubuntu 8.10
# 1  
Old 04-13-2009
Script Conversion To Ubuntu 8.10

I have a ping script I use on an old Open Step box (I guess its closely related to Mac OS X) and it runs fine, but now I built a system as a backup with Ubuntu 8.10 client and the script needs to be adapted a bit. Can anyone see where or how this needs to be done? The script starts and assigns the variables, but chokes on the ping portion of it which I think is syntax related

There are a few places where the end of the line is missing due to my copy and paste, but the main ping part that's broke is all there. I am hoping there is a substitution or something obvious I need to make throughout the script that will make it work again. Thanks!

Script
[CODE]#!/bin/sh

#[Path Statement]
PATH=/etc:/usr/etc:/usr/ucb:/bin:/usr/bin:/usr/local/bin:/usr/local/etc
SCRIPTNAME=`basename $0`

[Make Server List To Ping]
#this is the server list, with IP's and IP of the router
echo making server list
cat<<_EOF > /tmp/$SCRIPTNAME.serverlist
Albany1 xx.xx.xx.xx xx.xx.xx.1
_EOF

Code:
# establish the data directory
# function to ping the server. 
# if the server doesn't respond, find out if it is because the network
# leading to it is down.
# optionally specify the number of pings to send. default is 1.
# if more than one ping is sent, a response to any of the packets is
# considered up. down is only 100% packet loss.
#[PING PORTION]
sping()
{
NAME=$1
IP=$2
ROUTER=$3
if [ -n "$4" ]; then 
COUNT=$4
else
COUNT=1
fi
if ping $IP -c "$COUNT" | grep -s "100% packet loss"; then
if ping $ROUTER -c "$COUNT" | grep -s "100% packet loss"; then
echo "$NAME $IP $ROUTER (down because route to it is down)"
echo "$NAME $IP $ROUTER (down because route to it is down)" 1>&2
else
echo "$NAME $IP $ROUTER (down although route to it is up)"
echo "$NAME $IP $ROUTER (down although route to it is up)" 1>&2
fi
else
echo "$NAME $IP $ROUTER (up)"
echo "$NAME $IP $ROUTER (up)" 1>&2
fi
}

## [function to send the email notification with high or low importance]
notify()
{
echo "\n\nThis message sent by cron script /admin/scripts/crons/ping_servers.s
h on mpt1a01" > /tmp/$SCRIPTNAME.serverlist.explain
echo "Subject: RCP server stats\nImportance: $1 \n\n" | cat - /tmp/$SCRIPTNAME
.serverlist.upagain /tmp/$SCRIPTNAME.serverlist.wentdown /tmp/$SCRIPTNAME.server
list.stilldown /tmp/$SCRIPTNAME.serverlist.explain | /usr/lib/sendmail sam.lman@sbcglobal.net
cat /tmp/$SCRIPTNAME.serverlist.upagain /tmp/$SCRIPTNAME.serverlist.wentdown |
logger -t "ping_servers.sh" -p local4.err
}


# [make a list of servers that were down last time this script was run]
touch /admin/scripts/crons/$SCRIPTNAME.serverlist.down /admin/scripts/crons/$SC
RIPTNAME.serverlist.downlastrun
cp /admin/scripts/crons/$SCRIPTNAME.serverlist.down /admin/scripts/crons/$SCRI
PTNAME.serverlist.downlastrun

# [ping all the servers and accumulate a retry list]
echo pinging all the servers and accumulating a retry list
>/tmp/$SCRIPTNAME.serverlist.retry
while read NAME IP ROUTER
do
sping $NAME $IP $ROUTER | grep "(down" >>/tmp/$SCRIPTNAME.serverlist.retry
done</tmp/$SCRIPTNAME.serverlist


# [wait before retrying the down servers]
if [ -s /tmp/$SCRIPTNAME.serverlist.retry ]; then
echo waiting before retrying the down servers
sleep 10
else
echo no servers down
exit
fi


# [ping all the down servers with more packets to make sure they are down]
echo retrying down servers with more packets
> /admin/scripts/crons/$SCRIPTNAME.serverlist.down
while read NAME IP ROUTER OTHER
do
sping $NAME $IP $ROUTER 5 | grep "(down" >> /admin/scripts/crons/$SCRIPTNAME.s
erverlist.down
done</tmp/$SCRIPTNAME.serverlist.retry

# [look for differences]
# in this section, we are looking for what servers just went down,
# which ones just came back up, and which ones are still down from before
echo lists of recent downs and returns, and servers that remain down
>/tmp/$SCRIPTNAME.serverlist.wentdown
>/tmp/$SCRIPTNAME.serverlist.stilldown
>/tmp/$SCRIPTNAME.serverlist.upagain
while read NAME IP ROUTER
do
WASDOWN=`grep -w $NAME /admin/scripts/crons/$SCRIPTNAME.serverlist.downlastrun`
ISDOWN=`grep -w $NAME /admin/scripts/crons/$SCRIPTNAME.serverlist.down`
if [ -n "$WASDOWN" -a -n "$ISDOWN" ]; then
echo "$ISDOWN (still down)" >>/tmp/$SCRIPTNAME.serverlist.stilldown
fi
if [ -n "$WASDOWN" -a -z "$ISDOWN" ]; then
echo "$NAME $IP $ROUTER (up again)" >>/tmp/$SCRIPTNAME.serverlist.upagain
fi
if [ -z "$WASDOWN" -a -n "$ISDOWN" ]; then
echo "$ISDOWN (just went down)" >>/tmp/$SCRIPTNAME.serverlist.wentdown
fi
done</tmp/$SCRIPTNAME.serverlist
# cat /tmp/$SCRIPTNAME.serverlist.upagain /tmp/$SCRIPTNAME.serverlist.wentdown /
tmp/$SCRIPTNAME.serverlist.stilldown


# [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.we
ntdown ]; 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 | awk '{print $4}' | awk -F: '{print $1}'`" -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
else
echo no notification to make
fi

Last edited by gbxfan; 04-13-2009 at 07:29 PM.. Reason: CODE TAG ADDED
# 2  
Old 04-13-2009
Quote:
Originally Posted by gbxfan
I have a ping script I use on an old Open Step box (I guess its closely related to Mac OS X) and it runs fine, but now I built a system as a backup with Ubuntu 8.10 client and the script needs to be adapted a bit. Can anyone see where or how this needs to be done? The script starts and assigns the variables, but chokes on the ping portion of it which I think is syntax related

Have you read the man page for ping to see where its syntax differs from the Open Step version?
Quote:

There are a few places where the end of the line is missing due to my copy and paste,

Please edit your post and fix those places; you can't expect accurate help if we can't see exactly what you are doing.

While you're at it, please enclose the script in [code] tags.
Quote:

but the main ping part that's broke is all there.

Which part is that?

Have you tried just executing those parts (substituing reasonable values for the variables)?
Quote:
I am hoping there is a substitution or something obvious I need to make throughout the script that will make it work again. Thanks!
# 3  
Old 04-13-2009
Thanks for your time. I have placed the entire script (minus a few clients) and have tried to add tags for each section (if I understood you correctly - I hope this makes it easier) and have also added space between the sections. I appreciate your time in looking at this. I'll have to review the man pages and see if something pops out at me. Dale
# 4  
Old 04-13-2009

I repeat, "Please enclose the script in [code] tags".

And please answer the other questions.
# 5  
Old 04-13-2009
Thanks for your patience. Can you explain code tags (show me a small example?)and I will do my best to get them in there. Dale
# 6  
Old 04-13-2009
Quote:
Originally Posted by gbxfan
Thanks for your patience. Can you explain code tags (show me a small example?)and I will do my best to get them in there. Dale

Type [code] before your script and [/code ] (remove the space before the last ']') after it.

Or highlight the script and select the icon to add code tags.
# 7  
Old 04-13-2009
I hope I did this right, I have added the code tags - I thought they should be whereever processing is done? Please let me know. Thanks for your time. Dale
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script ouput conversion

Hi All, I am trying to print all the packages info in solaris 11 using below script. #!/usr/bin/env bash pkginfo -l | egrep '(BASEDIR|NAME|VERSION)' | awk '{print}' > /tmp/cp1 /usr/bin/nawk -F: ' {for (i=1; i<=NF; i++) {gsub (/^ *| *$/, "", $i) ... (5 Replies)
Discussion started by: sravani25
5 Replies

2. UNIX for Beginners Questions & Answers

powershell script to unix shell script conversion.

Here is a powershell script to use restful API to create ticket in our ticketing tool. Can anyone please convert it to a shell script sothat, I can run it in Unix servers, below is the code: $body = @{ Customer= ''test' Summary= 'test summary' Impact= '4-Minor/Localized' ... (2 Replies)
Discussion started by: pandeybhavesh18
2 Replies

3. Shell Programming and Scripting

Batch to shell script conversion

Hi All, I have a small tool which is currently configured in batch scripts only. But my need is to run it on Linux platform, so I have been trying to convert a batch script to shell script. below is the batch script: @echo off IF "%1"== "" GOTO ARGERR REM UPDATE THESE PROPERTIES TO... (2 Replies)
Discussion started by: sukhdip
2 Replies

4. Shell Programming and Scripting

Conversion of Perl Script to Shell Script..

Hi Guys I am having a perl script that fetches exclude list from a unix client and I trying it to convert it to shell script but I am having issues please help me... #!/usr/bin/perl use strict; use warnings; use Getopt::Std; # To turn on debuging (i.e. more information) specify... (29 Replies)
Discussion started by: Pawan Ramnani
29 Replies

5. Shell Programming and Scripting

Text to XML conversion using script

Hi I have a file in the format with so many records DB2 Universal JDBC Driver Provider,wdialdcsq,New JDBC Datasource,jdbc/wdialdcsq,,dcsqdb2n,cldrdgw1.is.chrysler.com,2998,DB2,10,1,180,0,1800 i need to convert all these into <DataSource name="wdialODDC" maxConnection="10" minConnection="0 "... (1 Reply)
Discussion started by: mskalyani9
1 Replies

6. Shell Programming and Scripting

Shell script for CSV conversion

thanks for allowing me join your forum i have an output of linux command "who" which provides following details..... CURRENT USER/ACCT INFO 17:31:36 up 4:49, 4 users, load average: 0.03, 0.04, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root :0 - 12:59 ?xdm? 4:54 0.02s /bin/sh /usr/bi... (1 Reply)
Discussion started by: ayyappancheta
1 Replies

7. AIX

Need timestamp conversion shell script !!

Can anyone provide me with a ksh or bash script which will accept a timestamp (format is YYYY-MM-DD-HH24.Mi.Ss) and time offset (in hours). The output will be (timestamp passed - time offset passed deducted from it) in the same YYYY-MM-DD-HH24.Mi.Ss format. Basically I am trying to convert the... (1 Reply)
Discussion started by: shibajighosh
1 Replies

8. Shell Programming and Scripting

Encoding conversion in PERL script

I have oracle 9i database installed with UTF-8 Encoding. I want a perl script that converts unicode to utf8 before commiting in database and utf8 to unicode when retreiving from database For example : the word Ïntêrnatïônàlîzâtion has to be stored in database as Internationalization and when retreived... (6 Replies)
Discussion started by: vkca
6 Replies

9. Windows & DOS: Issues & Discussions

unix script and unix2dos conversion

Hi, I am a newbie and do not have much experience using unix. But I have been trying to understand it. I found the following unix script typeset -i n=0 while do sleep 5 echo "${n}:Fluent is running...." n=${n}+1 done I have the following doubts: 1) In the first line - I am aware... (1 Reply)
Discussion started by: karthiksrao
1 Replies

10. Shell Programming and Scripting

shell script conversion to binary

My question is: i have a script called getevent to run i just call ./getevent can i convert this to make it binary executable and not letting my clients open it and see the code.??:( I am using Solaris 8. (3 Replies)
Discussion started by: bcheaib
3 Replies
Login or Register to Ask a Question