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

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

#! /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)

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?

#!/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

Yes /etc/defaultrouter is a single line as its a absolute path of a file name.

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.