 | Junior Member with 5 posts. | | Join Date: Aug 2007 Experience: Intermediate | | Help in writing a script in AIX!!! hi all,
i just started learning AIX.
i need your help in creating a script in AIX.
i want to check whether the internet links at my work are up or not.
if not the script shld send n sms stating the links ip address and a message tht the link is down.
and this script should run every 15 minutes.
i know i can use cronjob to make this script run every 15 minutes.
i can ping and store the ping result in a file.
i can sms the result to a mobile phone as well.
wat i cant do is to compare the result of the file which has ping result to make sure the file has reponse or no response so tht i can use the sms function correctly.
if neone can help me please!!! | | Distinguished Member with 14,989 posts. | | Join Date: Sep 2003 Location: -71.45091, 42.27841 | | Hi wildpunk,
Welcome to TSG!
If you use the Firefox browser, try the Mr. Uptime add-on extension which can be found here.
If this does not fit your requirement let us know that you still need to do the script.
Ok, I just saw this a few hours ago and posted before trying it. Apparently, Mr Uptime does not work for me - don't know if its just new (rel. 0.9.2) and still in testing or works better on other systems. I run Ubuntu Fiesty 7.04 knockoff aka Ultimate Ubuntu 1.4 Live CD - and the Preferences window did not come up in order to be able to set it.
WRT scripting the ping command, you can use the -c parameter as in:
ping -c 1 <url or ip address> and then check the result of the ping command via an echo $? command testing it in an if statement to put out up or down status.
At least that is the way I would write the shell script.
What shell are you using in AIX? sh, csh, zsh, tcsh?
-- Tom
__________________ The independence created by philosophical insight is - in my opinion - the mark of distinction
between a mere artisan or specialist and a real seeker after truth. - Einstein 1944
Imagination is more important than knowledge. - Einstein
Last edited by lotuseclat79 : 21-Aug-2007 02:05 PM.
| | Junior Member with 5 posts. | | Join Date: Aug 2007 Experience: Intermediate | | hi tom,
thanks for a fast reply.
to start with i m using korn shel---ksh.
i did the same watever u said.
i started my script with a ping - c command and stored the result in a file called pingresult.txt
now i dunno how to run a if statement to check the contents of the file means
how can i run if statement to check whether the file has replies or request timed out.
so tht i can do the needfull step.
hope this answers ur question.
thanks
Tapan | | Distinguished Member with 14,989 posts. | | Join Date: Sep 2003 Location: -71.45091, 42.27841 | | Hi wildpunk,
ksh will be able to process sh commands readily.
Here's a snippet for you to try:
ping -c 1 <url>
if [ $? = 0 ]; then <up>; else <down>; fi
You could also try putting the two stmts above in a while loop with a wait stmt where the argument to the wait stmt is in seconds, i.e. 900=15 minutes:
while <down>
ping -c 1 <url>
if [ $? = 0 ]; then <up>; else <down>; fil
wait 900
end
Read the man page to learn the syntax of scripting, or better yet use Google, like this to search for a tutorial on scripting zsh:
Google search box: zsh +tutorial +scripting
-- Tom
__________________ The independence created by philosophical insight is - in my opinion - the mark of distinction
between a mere artisan or specialist and a real seeker after truth. - Einstein 1944
Imagination is more important than knowledge. - Einstein | | Junior Member with 5 posts. | | Join Date: Aug 2007 Experience: Intermediate | | hi tom,
i really appricaite ur help.
Here's a snippet for you to try:
ping -c 1 <url>
if [ $? = 0 ]; then <up>; else <down>; fi
now in the above exp use used $? wats this for.
now n how can i comapre the count
if i do ping -c 1 <url>
it is supposed to ping the url only once.
if it is up it will give me one reply otherwise no replies.
but how can i make sure it gave me a reply so tht i can compre with the $? variable.
i m trying to do man on commands.
but thr are somethins which man cant help out with,
i m using google as well.
thanks for all the help.
waitin for ur reply | | Distinguished Member with 14,989 posts. | | Join Date: Sep 2003 Location: -71.45091, 42.27841 | | Execute the command: ping -c 1 <url> replacing <url> with a web address either by name or ip address.
Immediately afterwards issue the command: echo $?
The return code of the ping command preceeding the echo command is output. A '0' return code indicates the website is up, anything else and most likely the ping command will have 100% packet loss.
ping -c 1 <url> only pings the ,url. once.
The echo $? output is the reply where 0 = up anything else means not accessible.
You do not need more than one count to compare, just use the echo $? output with a count = 1, then check it like in the code snippet and replacing <up> and <down> with the action/command(s) you want. Don't forget to wait 900 for 15 minutes.
-- Tom
__________________ The independence created by philosophical insight is - in my opinion - the mark of distinction
between a mere artisan or specialist and a real seeker after truth. - Einstein 1944
Imagination is more important than knowledge. - Einstein | | Senior Member with 130 posts. | | | | in some corporations, ping is disallowed. Internet access may be through some proxy servers. If you want to check whether the your internet is up...you can
1) use wget to download a webpage. If you can view the web page, it means your internet is
2) use languages like Perl/Python that has HTTP libraries so you can code your own script to download a web page and grab their contents. | | Junior Member with 5 posts. | | Join Date: Aug 2007 Experience: Intermediate | | hi tom,
y are we using wait 900 here.
i will be assigning this script a cronjob which will run every 10 minutes.
do i still have to use wait for this? | | Junior Member with 5 posts. | | Join Date: Aug 2007 Experience: Intermediate | | just one more question.
wat if i do
ping -c 1 <url> >output.txt
grep -c "ttl" output.txt
grep -c will show me the count of ttl
which will be 1 if link is up 0 if link is down.
but i dunno how can i use this value to compare.
grep just displays it on screen.
is thr any way to store it in a variable. | | Distinguished Member with 14,989 posts. | | Join Date: Sep 2003 Location: -71.45091, 42.27841 |
23-Aug-2007, 06:57 AM
#10 | Quote: |
Originally Posted by wildpunk hi tom,
y are we using wait 900 here.
i will be assigning this script a cronjob which will run every 10 minutes.
do i still have to use wait for this? | No, only if you don't run a cronjob and run the script from a terminal window instead. Adn 900 represents 15 minutes of wait time, 600 would be 10 minutes.
-- Tom | | Distinguished Member with 14,989 posts. | | Join Date: Sep 2003 Location: -71.45091, 42.27841 |
23-Aug-2007, 07:08 AM
#11 | Quote: |
Originally Posted by wildpunk just one more question.
wat if i do
ping -c 1 <url> >output.txt
grep -c "ttl" output.txt
grep -c will show me the count of ttl
which will be 1 if link is up 0 if link is down.
but i dunno how can i use this value to compare.
grep just displays it on screen.
is thr any way to store it in a variable. | Hi wildpunk,
First, ttl is the time to live. For example, when I issue the ping command:
$ ping -c 1 forums.techguy.org
I get the output:
ping -c 1 forums.techguy.org
PING forums.techguy.org (209.183.226.152) 56(84) bytes of data.
64 bytes from www.techguy.org (209.183.226.152): icmp_seq=1 ttl=55 time=143 ms
--- forums.techguy.org ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 143.805/143.805/143.805/0.000 ms
Note the ttl value above, i.e. ttl does not represent what you think it does.
If the ping command returns other than a 0, the site is down. As I have been recommending all along:
ping -c 1 <url>
if [ $? = 0 ]; then <up command action>; else <down command action>; fi
end
-- Tom
__________________ The independence created by philosophical insight is - in my opinion - the mark of distinction
between a mere artisan or specialist and a real seeker after truth. - Einstein 1944
Imagination is more important than knowledge. - Einstein | | Junior Member with 3 posts. | | |
30-Aug-2007, 01:38 PM
#12 | Urgent help in scripting in Solaris AIX Hi
We have some shell scripts running perfectly on Solaris box ….
Recently we got a new server ( AIX ) and we are supposed to move few applications using these scripts on it.
Just wanted your opinion on whether we can run those scripts without any changes on AIX box or it will require some alterations ? | | Distinguished Member with 14,988 posts. | | Join Date: Apr 2003 Location: 1265 Lombardi Ave Experience: IIAHYAYCESA,YAADA! |
31-Aug-2007, 08:34 PM
#13 | | |  THIS THREAD HAS EXPIRED.
Are you having the same problem?
We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.
|
Smart Search
| Find your solution! | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |  WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
| You Are Using: |
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 07:55 AM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd. | |
|