LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-11-2009, 05:59 AM   #1
ziggy25
Member
 
Registered: Aug 2005
Distribution: Debian 5.2
Posts: 56

Rep: Reputation: 15
How does this simple awk script work?


This script is supposed to find out if tomcat is running or not.

Code:
#!/bin/sh
if netstat -a | grep `grep ${1}:  /tomcat/bases | awk -F: '{print $3}'` > /dev/null
then
        echo Tomcat for $1 running
else
        echo Tomcat for $1 NOT running
fi
the /tomcat/bases is a file that contains a list of all the tomcat instances running and which port number it is running
Code:
user1:yes:8080
user2:no:8081
user3:yes:8082
I know it uses netstat to check if any of the port numbers in the "bases" file is listening but i dont quite understand how this is achieved by that command shown above.

Thanks
 
Old 12-11-2009, 07:14 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

netstat -a | grep `grep ${1}: /tomcat/bases | awk -F: '{print $3}'` > /dev/null

First the blue part is executed (all between both backticks), which gives back a specific port (field number 3 in /tomcat/bases) associated with the user (which is given at the command line, represented by $1). The awk command sets a different field separator (default is a space, -F: makes it a : ).

You end up with a command like this (when user1 is used at the command line):

netstat -a | grep 8080 > /dev/null

Depending on the output the process is either alive or not.

Hope this clears things up a bit.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use "awk" to do the following seemingly simple work? lawrence_lee_lee Linux - Software 1 04-17-2008 05:29 AM
Very simple script does not work....? M$ISBS Programming 7 01-28-2008 04:18 PM
simple awk script question adam_blackice Programming 9 09-03-2007 03:23 PM
why this simple cgi script doesnot work ? . adam_blackice Programming 4 04-04-2007 11:50 AM
Simple script won't work compused Linux - Newbie 4 11-22-2006 07:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration