![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| script to ping servers | sriny | UNIX for Advanced & Expert Users | 2 | 01-23-2008 09:19 AM |
| 3 servers 1 .ksh script | cml2008 | UNIX for Dummies Questions & Answers | 2 | 01-20-2008 04:23 PM |
| Script behaving differently on two servers | mhssatya | UNIX for Advanced & Expert Users | 5 | 09-13-2006 02:28 PM |
| Howto locate locally installed Perl module for a CGI script in APACHE .htaccess | monkfan | UNIX for Dummies Questions & Answers | 0 | 05-18-2006 09:55 PM |
| login into multiple servers thru script... | avcert1998 | Shell Programming and Scripting | 1 | 09-09-2005 03:38 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
script to locate servers
I am a newbie in shell scripting and I need to produce a script to work and achieve the following:
1) Look into the file /etc/defaultrouter , and store the value in it 2) If the value is a number, go to LIST and print out the second column corresponding to the value.(eg London) 3) If the content of /etc/defaultrouter is not a number then go to /etc/host to check for the corresponding number 4) Get the number in step 3 and execute step 2 Content of LIST 22.123.2.1.1 canada 192.11.2.1 india 177.235.1.1.1 spain 172.44.5.1 london 66.112.4.1 newyork |
|
||||
|
script to locate server
I am moVing forward with this script, thanks to joeyg. However i am still having problem with the line highlighted in red. I actually want the script to check the value of invalue if it contain alperbert, if yes, then go to /etc/host.
i have the script bellow but i keep getting the error; ./locatenew.sh: line 13: syntax error near unexpected token `="[a-z]"' ./locatenew.sh: line 13: `(cat $invalue |grep [a-z]) ="[a-z]" ' ( line 13 is highlighted in red in my script bellow). I am a newbiee to scripting. #! /bin/bash #set variables invaluef="/etc/defaultrouter" lookupt="LIST" hostf="/etc/host" #read input file to get starting value invalue=$(cat $invaluef) #check if the value of $invalue is alphabet if (cat $invalue |grep [a-z]) ="[a-z]" then listword =$(cat $hostif |grep "^$invalue" | cut -d" " .f1) listloc=$(cat $lookupt | grep "^$listword" | cut -d" " -f2) else fi #lookup value in file, getting 2nd field listloc=$(cat $lookupt | grep "^$invalue" | cut -d" " -f2) echo This server is located in $listloc |
|
||||
|
You don't need parentheses in this particular construct anyway, so just take them out. Your syntax for comparing the output is not correct, though.
Anyway, this looks needlessly complicated. Perhaps simplifying the script would be a better way to spend your time. Is /etc/defaultrouter a single line? Code:
#!/bin/sh
read value </etc/defaultrouter
case $value in
*[!.0-9]*) value=`awk -v v="$value" 'v { print $1 }' /etc/hosts` ;;
esac
awk -v v="$value" '$1 == v { print $2 }' LIST
Last edited by era; 05-29-2008 at 06:53 AM.. Reason: Misdiagnosed the problem; restructure beginning of posting |
|
||||
|
Point being, are the contents of the file a single line, or multiple lines? Assuming it's a single line, the script I posted should do what you asked for, if I correctly interpreted your requirements.
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|