1833445 Members
2904 Online
110052 Solutions
New Discussion

Script problem

 
Jeff Picton
Regular Advisor

Script problem

Please see the script below. Whenever I run it , I get unknown host name. I do not know why

#!/usr/bin/sh

if [ $# -lt 1 ]
then
echo "\nUsage: $0 "
exit 1
fi

HOST=$1
A=`/usr/bin/grep $HOST /etc/hosts | awk '{print$2}' | wc -l`
if [ A -gt 0 ] then
# Run remote shell to remote host and export display
exec /usr/bin/remsh $HOST -n /usr/bin/X11/dtterm -display $DISPLAY
-ls -title $HOST -n $HOST -sb -sl 500 &
else
echo "Unknown host...please try again"
fi
done
8 REPLIES 8
Mark Grant
Honored Contributor

Re: Script problem

I think you missed out a $ here

if [ A -gt 0 ] then


It should be

if [ $A -gt 0 ]

Those are the really annoying ones!
Never preceed any demonstration with anything more predictive than "watch this"
Jeff Picton
Regular Advisor

Re: Script problem

Hi

No I still get the same answer
Umapathy S
Honored Contributor

Re: Script problem

Jeff,
Does that host is listed in /etc/hosts?

HTH,
Umapathy
Arise Awake and Stop NOT till the goal is Reached!
Mark Grant
Honored Contributor

Re: Script problem

Shame,

Ok, firstly

That whole line looks a bit overly complicated to me.

How about

grep $HOST /etc/hosts > /dev/null && {
exec /usr/bin/remsh $HOST -n /usr/bin/X11/dtterm -display $DISPLAY -ls -title $HOST -n $HOST -sb -sl 500 &
exit
}

echo "Unknown host.... please try again"
Never preceed any demonstration with anything more predictive than "watch this"
Pete Randall
Outstanding Contributor

Re: Script problem

Jeff,

change

if [ A -gt 0 ] then

to

if [ A -gt 0 ]; then



and try it.


Pete


Pete
Jeff Picton
Regular Advisor

Re: Script problem

Hi

Thanks for all that answered.

Firstly I was running the script from the wrong area and it was picking up the wrong executable.

Secondly its Friday...doh

This now works.
H.Merijn Brand (procura
Honored Contributor

Re: Script problem

and drop the awk part. counting lines with wc -l will not change if the line is shorter :)

if [ `grep $HOST /etc/hosts | wc -l` -gt 0 ]; then

And grep returns a status, so you don't even need the wc, see MArk's example

Enjoy, have FUN! H.Merijn

Enjoy, Have FUN! H.Merijn
Peter Nikitka
Honored Contributor

Re: Script problem

Hi,

please consider:
if the whole stuff is tried in an NIS or DNS environment, depending on /etc/nswitch.conf it
may be totally meaningless, if 'grep' succeeds in
/etc/hosts or not ...

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"