The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-27-2008
ibroxy ibroxy is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 19
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
  #2 (permalink)  
Old 05-27-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Red face here is a start...

You did not provide much in details are example info. But, the following is a start to your logic:

Code:
#! /bin/bash

#set variables
invaluef="/etc/defaultrouter"
lookupt="LIST"
hostf="/etc/host"

#read input file to get starting value
invalue=$(cat $invaluef)
echo $invalue

#lookup value in file, getting 2nd field
listloc=$(cat $lookupt | grep "^$invalue" | cut -d" " -f2)
  #3 (permalink)  
Old 05-29-2008
ibroxy ibroxy is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 19
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
  #4 (permalink)  
Old 05-29-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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
  #5 (permalink)  
Old 05-30-2008
ibroxy ibroxy is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 19
Yes /etc/defaultrouter is a single line as its a absolute path of a file name.
  #6 (permalink)  
Old 05-30-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:39 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0