LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need help in a script for server information (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-in-a-script-for-server-information-876140/)

austinbravo 04-20-2011 11:15 AM

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.

MensaWater 04-20-2011 11:25 AM

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.


All times are GMT -5. The time now is 06:25 PM.