There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Linux and Unix
Tag Cloud
access acer asus bios bsod computer crash driver drivers error ethernet excel freeze gaming google gpu graphics hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry repair router security slow software sound trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
Help in writing a script in AIX!!!

Reply  
Thread Tools
wildpunk's Avatar
Junior Member with 5 posts.
 
Join Date: Aug 2007
Experience: Intermediate
21-Aug-2007, 10:36 AM #1
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!!!
lotuseclat79's Avatar
Distinguished Member with 21,345 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
21-Aug-2007, 02:17 PM #2
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 at 03:05 PM..
wildpunk's Avatar
Junior Member with 5 posts.
 
Join Date: Aug 2007
Experience: Intermediate
21-Aug-2007, 06:41 PM #3
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
lotuseclat79's Avatar
Distinguished Member with 21,345 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
21-Aug-2007, 08:08 PM #4
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
wildpunk's Avatar
Junior Member with 5 posts.
 
Join Date: Aug 2007
Experience: Intermediate
21-Aug-2007, 08:39 PM #5
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
lotuseclat79's Avatar
Distinguished Member with 21,345 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
22-Aug-2007, 10:56 AM #6
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
ghostdog74's Avatar
Member with 146 posts.
 
Join Date: Dec 2005
22-Aug-2007, 11:27 AM #7
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.
wildpunk's Avatar
Junior Member with 5 posts.
 
Join Date: Aug 2007
Experience: Intermediate
22-Aug-2007, 06:28 PM #8
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?
wildpunk's Avatar
Junior Member with 5 posts.
 
Join Date: Aug 2007
Experience: Intermediate
22-Aug-2007, 08:27 PM #9
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.
lotuseclat79's Avatar
Distinguished Member with 21,345 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
23-Aug-2007, 07: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
lotuseclat79's Avatar
Distinguished Member with 21,345 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
23-Aug-2007, 08: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
rahul_r_k's Avatar
Junior Member with 3 posts.
 
Join Date: Aug 2007
30-Aug-2007, 02: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 ?
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
31-Aug-2007, 09:34 PM #13
You should probably look into using some of the very good Open source network monitoring software.
My friend is the Admin for a very large school system and he runs Nagios.
http://www.nagios.org/

Or run nagios and splunk.
http://www.nagios.org/products/enter...utions/splunk/
Reply

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.

Search Tech Support Guy

Find the solution to your
computer problem!




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.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 06:30 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.