can't get this code to work


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers can't get this code to work
# 1  
Old 12-12-2003
Network Ping hosts PLEASE HELP!

Ok I have just started using UNIX and am trying to write a script that will ping a list that I have created in a file called ipaddesses
I need to get it to find the ip address that is not in use and do nothing however if it finds that all ip addresses have been taken to send me an e-mail!

the system is on SUN Solaris v8 and I am absalutly stuck I don't want to use grep to do it as i would have to know what all possible error messages are.
PLEASE HELP
Regards
a very troubled Jono

Last edited by jono; 12-12-2003 at 12:41 PM..
# 2  
Old 12-13-2003
Since you are pinging IP addresses, there should be a default of only two responses. Alive or not. If you were pinging host names, then you might get into a problem of the hostname is unknown (could not be found in /etc/hosts, DNS, NIS, ...).

Read the man page on ping - add in the timeout parameter (I'm not on my systems right now to check it)
$ ping 10.140.1.40|grep -i alive
or
$ ping 10.140.1.40|grpe -ic alive

The second would give you either 0 or 1 as the "answer". Go from there....
# 3  
Old 12-13-2003
Big thanks!

Thankyou mate thats really good!
just should I send the results to a file in they aren not alive? and if they aren't alive is their away of testing that the file has lines in which case it send a mail saying ip addresses all in use? if you get what I mean?
Thanks for that though!
Jono
# 4  
Old 12-13-2003
Computer think this is what I have! but not sure it'll work

Code:
#!/bin/sh

for a in `cat ipaddresses`
do 
   if
    /usr/sbin/ping $a|grpe -ic alive
    break
   else
mail "email address" <<!!!
message
!!!
fi
done

ok I am thinking that this will find the first ip address that didn't return the alive value and exit or if all IP addresses ping then send an e-mail is this right?/?//?


the file is called ipaddresses and contains several ip addresses in $1 example I need it to check each ipaddress!

IPADDRESSES (file name)

160.60.224.1
160.60.224.2
160.60.224.3
160.60.224.4
160.60.224.5

Regards
Jono

added code tags for readability --oombera

Last edited by oombera; 02-20-2004 at 10:47 AM..
# 5  
Old 12-15-2003
can't get this code to work

#!/bin/sh

for a in `cat ipaddresses`
do
/usr/sbin/ping $a|grep -ic alive
exit 0
else
mail jshwood <<!!!
message
!!!
done


please help!
Regards
Jono

Last edited by jono; 12-15-2003 at 05:25 AM..
# 6  
Old 12-15-2003
No tested, try it.

#!/bin/sh

for a in `cat ipaddresses`
do
if /usr/sbin/ping $a|grep -ic alive
then
/usr/sbin/ping $a|grep -ic alive
else
mail jshwood <<!!!
message
!!!
fi
done
# 7  
Old 12-15-2003
Ok its nearly there

I need it to e-mail me if all ip addresses are taken!
sorry I probably didn't explain that that well!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. IP Networking

Discussion at work, would a router work pluging a cable in wan1 and lan1?

hi all. and sorry for the random question, but this sparkled a raging flame-war at work and i want more points of view situation a router, with linux of some sort, dhcp client requesting for ip in wan1 (as usual with wan ports) dhcp server listening in lan1, and assigning ip (as usual... (9 Replies)
Discussion started by: broli
9 Replies

2. Shell Programming and Scripting

My code worked on a Mac, now it does not work in another computer

I guess Mac has default bash. Then I copy my code to another comp and run it...And it gives me an error like "bad substitution".... How I can change my code??? Never had before this kind of situation. Help please. if then n=$(sort /Users/Natalie/lastserial | tail -1) ... (6 Replies)
Discussion started by: Natalie
6 Replies

3. Programming

Breakpoints dont work in Codeblocks, code does not build

Hey so I've written a program and it crashes every time I run it. I tried placing breakpoints to see what was going but to my surprise they do not work! I've placed them anywhere and they do not stop the execution of the program. In fact if I add code and hit rebuild it doesn't even build that... (1 Reply)
Discussion started by: Cambria
1 Replies

4. Shell Programming and Scripting

My script work on Linux but not work in sunos.

My script work on Linux but not work in sun os. my script. logFiles="sentLog1.log sentLog2.log" intial_time="0 0" logLocation="/usr/local/tomcat/logs/" sleepTime=600 failMessage=":: $(tput bold)Log not update$(tput rmso) = " successMessage="OK" arr=($logFiles)... (7 Replies)
Discussion started by: ooilinlove
7 Replies

5. UNIX for Dummies Questions & Answers

why my code does not work?

Hi there can anyone help me why my code is saying Badly placed ()'s. #!/bin/csh if ($#argv != 1) then echo "One file is required" exit 1 else set lines=(`grep '404' $1 | cut -d" " -f5`) foreach line ($lines) printf ("Abnormal sites: %s\n", $line) endif thanks in advance! :) (7 Replies)
Discussion started by: FUTURE_EINSTEIN
7 Replies

6. IP Networking

NIC will not work, but it did work.

I have a client machine that was built and loaded with SCO UNIX 2.1.3, (yes it is old). The machine worked fine on the closed network that I tested on in my shop. I then had to change it to the network that it would be connected to. Below is the host file, router and subnet mask file that I usually... (0 Replies)
Discussion started by: NC user
0 Replies

7. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

8. Programming

why the code cant work?

I'am new in C programming in UNIX. the code is as following: --------------------------------- #include<stdio.h> #include<unistd.h> int main() { printf("pid=%d\n",getpid()); return 0; } ---------------------------------- when I compile it(gcc) it output errors: Undefined ... (4 Replies)
Discussion started by: Namely
4 Replies
Login or Register to Ask a Question