script to locate servers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to locate servers
# 1  
Old 05-27-2008
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  
Old 05-27-2008
Power 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  
Old 05-29-2008
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  
Old 05-29-2008
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 07:53 AM.. Reason: Misdiagnosed the problem; restructure beginning of posting
# 5  
Old 05-30-2008
Yes /etc/defaultrouter is a single line as its a absolute path of a file name.
# 6  
Old 05-30-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash Script Locate Word Failed

I'm using CentOS 7 and I would like to know of a way to read each line and search for a specific word. For example, if it finds the word "Fail" it sends it to a variable, and pipes it to a folder on the network. What would be the best way in making this work in a Linux environment? I wrote a... (1 Reply)
Discussion started by: SysAdminRialto
1 Replies

2. Shell Programming and Scripting

Script to locate date in filename

I am looking for a way to find a date in the file without using find. for example something like this: files=`ls |grep txt` YEST=`TZ="GMT+24" date +'%m-%d-%Y'|sed 's/^0//g' |sed 's/$/.txt/g'` YES1=`TZ="GMT+48" date +'%m-%d-%Y'|sed 's/^0//g' |sed 's/$/.txt/g'` if ]; then echo yes;else echo... (4 Replies)
Discussion started by: newbie2010
4 Replies

3. UNIX and Linux Applications

Call one script from other script lying on different servers.

HI All, I have a requirement of execueting a Shell script on serverA, which is going to execute an application script ( Hyperian Planning script ) on serverB. Can any one please help in how to achieve this? e.g. script abc.ksh runs on serverA. internally abc.ksh call a script... (3 Replies)
Discussion started by: alok2082
3 Replies

4. Shell Programming and Scripting

Script to Ping Servers

Hey, It's me again! Still trying to learn to become a better scripter on the job :) New challenge for assistance, if anyone cares to help, and its two parted! First part, I wanted to create a script at work that would ping a server that was supplied in an argument, then a count (amount of times)... (5 Replies)
Discussion started by: gkelly1117
5 Replies

5. UNIX for Advanced & Expert Users

Tring to locate a script

Hello, We have a process on our Linux RedHat machine creating symbolic links and moving around some files from domain to domain. The issue is that the programmer has left a long time ago and nobody knows how the program is called, where it is and how the scheduling is setup. It runs every day for... (7 Replies)
Discussion started by: Indalecio
7 Replies

6. Shell Programming and Scripting

Need bash script to ping the servers and rename the output file each time the script is ran

HI, I have a file serverlist in that all host names are placed. i have written a small script #./testping #! /bin/bash for i in `cat serverlist` do ping $i >> output.txt done so now it creates a file output.txt till here fine.. now each time i run this script the output file... (4 Replies)
Discussion started by: madhudeva
4 Replies

7. Shell Programming and Scripting

Script to locate Thunderbird message filter

#!/bin/sh #Finds the directory where usually the message folder information is for Thunderbird. clear cd ~/ cd .thunderbird dir=$(dir) echo $dir echo "What is the name of your .default directory?" read userinput echo "Your Thunderbird Message Filter msgFilterRules.dat files are in the... (1 Reply)
Discussion started by: edcompsci
1 Replies

8. Shell Programming and Scripting

df -kh on 30+ servers using script?

It feels like I have taken on to of a big task.. but I want to learn but dont know where to start.. Rome wasnt built in one day right.. I have around 30+ servers running linux/unix flavours and need to be able to do this in a script that will be a cronjob. - ssh to all 30+ servers - do df -kh... (3 Replies)
Discussion started by: ebolasmurf
3 Replies

9. UNIX for Advanced & Expert Users

script to ping servers

Hi , I would like to automate a script to ping all the unix servers perodically thru cronjob. Is there any script out there? If so Please give me. Thanks in advance. (2 Replies)
Discussion started by: sriny
2 Replies

10. UNIX for Dummies Questions & Answers

Howto locate locally installed Perl module for a CGI script in APACHE .htaccess

Hi, I have the following simple CGI script, just containg header: #!/usr/bin/perl -w use CGI ':standard'; use lib "/home/myname/lib/perl5/site_perl/5.8.5/"; use Mail::Sendmail; I also have included this directive in ~/public_html/.htaccess : SetEnv PERL5LIB... (0 Replies)
Discussion started by: monkfan
0 Replies
Login or Register to Ask a Question