LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 04-20-2011, 11:15 AM   #1
austinbravo
LQ Newbie
 
Registered: Jul 2008
Posts: 23

Rep: Reputation: 0
Need help in a script for server information


Hello Geeks,

I am new to Scripting. My task is to create a script that would pull the old server(unix) and new server(linux) information and should display all the task information for migration/cutover purpose to the other areas.

We already have a script that gives information about ip, subnet, gateway and other information as follows:

#readip ad30db01
Server IP Subnet Gateway VLAN
10.x.x.x 255.x.x.x 10.x.x.1 100

There is a main server which has info about all the servers and we execute the readip from the main server which gets info about any old or new server.

So, in my script, I am calling this script, and I want to display only few contents of the readip output as follows:

Hostname: (I should display the server ip from the read ip only out)
Subnet: Should display the subnet from the readip output
Gateway: Same
Vlan: Same

If anyone could help me with this part, I would include it in my script and would ask for the next part if I don't get it.

Please let me know if I am not clear.

Thank you.
 
Old 04-20-2011, 11:25 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,716
Blog Entries: 14

Rep: Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039
Code:
for server in <list>
do set $(readip $server |grep -v ^Server)
   echo Hostname: $1
   echo Subnet: $2
   echo Gateway: $3
   echo Vlan: $4
done
The items inside the parentheses get the line that has the information you want and excludes the header line. The "set" command makes them positional parameters. The rest of the script simply prints the literal text you want and the positional parameter for each. (Note that IP is NOT really "hostname" but that is what you asked for. You might want to put $server there instead of $1 for a name.)

You would substitute "<list>" with whatever you want for list. e.g. It could be:
for server in ad30db01 ad30db02 ad30db03
--OR--
If you had a file that had a list of servers in it:
for server in $(cat <file>)
where <file> is replaced with the name of the actual file in which the servers are listed.

Last edited by MensaWater; 04-20-2011 at 11:27 AM.
 
  


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
Script to copy information only after a certain sequence amymarma Linux - Newbie 3 06-24-2009 07:20 PM
%Post Script Information!!! lunatichead Programming 1 09-22-2008 06:20 AM
Outputting information from my script to a webpage circuit_girl Programming 3 09-28-2006 02:59 PM
Battery level information script d0odman Linux - Laptop and Netbook 1 01-21-2006 01:41 PM
What is script PID information? Stepaj47 Linux - Newbie 7 11-15-2005 02:50 PM


All times are GMT -5. The time now is 01:26 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration