Complex ksh variable

Hello Experts,

  Here is the question:

   This is works:

     HOSTNAME=/usr/bin/hostname
     $HOSTNAME - output: "demohost"

   This is not:

     HOST_DOMAIN="(/usr/bin/hostname | xargs /usr/sbin/nslookup | grep Name | awk '{print \$2}')"

    $HOST_DOMAIN - output: "ksh: (/usr/bin/hostname:  not found"

   At the same time, this runs okay:

(/usr/bin/hostname | xargs /usr/sbin/nslookup | grep Name | awk '{print $2}')

 Output: demohost.domain.com

 Please, help me with the right way of asigning $HOST_DOMAIN, so it will return <hostname>.<domain>, i.e.

  $HOST_DOMAIN, output: demohost.domain.com

Thanks,

 rwarsh



   
LVL 3
Ron WarshawskyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Computer101Connect With a Mentor Commented:
PAQed - no points refunded (of 100)

Computer101
E-E Admin
0
 
biraCommented:
HOST_DOMAIN=`(/usr/bin/hostname | xargs /usr/sbin/nslookup | grep Name | awk '{print $2}')
`
0
 
Ron WarshawskyAuthor Commented:
to Bira:

 Did you test it before sumbitting? Your statement does not works.

rwarhs

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
biraCommented:
what is the result if you fire   echo $HOST_DOMAIN   ?

what kind of unix do you have ?
0
 
biraCommented:
Try this way:
HOST_DOMAIN=`/usr/bin/hostname | xargs /usr/sbin/nslookup | grep Name | awk '{print $2}'`

 echo $HOST_DOMAIN

  What does it show ?
0
 
Ron WarshawskyAuthor Commented:
These are the results:

$ HOST_DOMAIN="(/usr/bin/hostname | xargs /usr/sbin/nslookup | grep Name | awk '{print \$2}')"
$ echo $HOST_DOMAIN
(/usr/bin/hostname | xargs /usr/sbin/nslookup | grep Name | awk '{print $2}')
$ $HOST_DOMAIN
ksh: (/usr/bin/hostname:  not found

However,

This command will provide ok result:

$ (/usr/bin/hostname | xargs /usr/sbin/nslookup | grep Name | awk '{print $2}')



0
 
yuzhCommented:
use:
  HOST_DOMAIN=`nslookup \`hostname\` | grep Name
| awk '{print $2}'`

  echo $HOST_DOMAIN

0
 
Ron WarshawskyAuthor Commented:

 To yuzh:

  Your command will provide with the immediate computation of the HOST_DOMAN. Please, see the original question above:

 The point is to be able to have a set of commands in a text variable and beeing able to use it like:

 local_host = $($HOST_DOMAIN) or

 remsh <hostname> -l <user> $HOST_DOMAIN,

 where HOST_DOMAIN is set of the commands, not a result

 Thanks,

  rwarsh




0
 
yuzhCommented:
Ok , you want to store the set of commands to a var, here's
the one:

HOST_DOMAIN="nslookup \`hostname\` | grep Name | awk '{print \$2}'"

to verify what's in the var, use

echo $HOST_DOMAIN

to run the command:

use: eval $HOST_DOMAIN

Cheers!


0
 
Ron WarshawskyAuthor Commented:

 Hello yuzh,

  Unfortunately, I am changing existing system(very big), written in ksh and I can not use "eval".

 The change suppose to substitute statement

 HOSTNAME=/usr/bin/hostname

 with the working version of

 HOSTNAME=="nslookup \`hostname\` | grep Name | awk '{print \$2}'"

 This variable called later in different parts of code, using $($HOSTNAME) and in rsh call.

Thanks,

 rwarsh

0
 
ozoCommented:
HOST_DOMAIN=`/usr/bin/hostname | xargs /usr/sbin/nslookup | grep Name | awk '{print $2}'`
0
 
Ron WarshawskyAuthor Commented:

 to ozo:

   Please, see my comment on bira's suggestion. Your statement is the same one.

rwarsh
0
 
ahoffmannCommented:
HOST_DOMAIN='/usr/sbin/nslookup '"'"'`'"'"'/usr/bin/hostname'"'"'`'"'"'|awk '"'"'/^Name/{print $2}'"'"

rsh host $HOST_DOMAIN
0
 
Ron WarshawskyAuthor Commented:

 To ahoffman,

  Please, try it on command line, like

    $($HOST_DOMAIN) - it will fail.

  Actually, even simple example will fail,

  i.e.

   Works:
    >a="ls -al"
    >$a
   
   Does not works:

   >a="(ls -al | grep .txt)"
   >$a
    ksh: (ls:  not found - error.



   
   
   
   
0
 
ahoffmannCommented:
I did not use parantheses, and not $($HOST_DOMAIN)
my simple example works for me (but it is pdksh on Linux, which should not be a problem here)
0
 
Ron WarshawskyAuthor Commented:

To ahoffman:

  My UNIX is SunOs 5.8

rwarsh
0
 
ahoffmannCommented:
HOST_DOMAIN='/usr/sbin/nslookup `/usr/bin/hostname`|awk '"'"'/^Name/{print $2}'"'"
rsh host $HOST_DOMAIN
0
 
DigitalGuyCommented:
Try this.  It works on Solaris 5.6.

HOSTNAME="`hostname`.`cat /etc/resolv.conf | awk '{if ($1 == "domain") print $2}'`"

You can then access using $HOSTNAME

0
 
jmcgOwnerCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ with points refunded

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0
 
jmcgOwnerCommented:
The experts seemed to have a hard time seeing what rwarsh was trying to do. They kept on answering a different question than he was asking.
0
 
ahoffmannCommented:
may suggestion (http:#7025363) works in ksh
no reason for a refund
0
 
jmcgOwnerCommented:
I'm not sure why rwarsh rejected your solution, since I'm not entirely sure I understand what he was asking for myself. The moderator may see things differently than I did.
0
 
Computer101Commented:
PAQed, with points refunded (100)

Computer101
E-E Admin
0
 
ahoffmannCommented:
Computer101, would you please explain your choice
0
All Courses

From novice to tech pro — start learning today.