Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Complex ksh variable

Posted on 2002-05-20
26
Medium Priority
?
891 Views
Last Modified: 2008-03-10
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



   
0
Comment
Question by:Ron Warshawsky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 3
  • +5
26 Comments
 
LVL 6

Expert Comment

by:bira
ID: 7022619
HOST_DOMAIN=`(/usr/bin/hostname | xargs /usr/sbin/nslookup | grep Name | awk '{print $2}')
`
0
 
LVL 3

Author Comment

by:Ron Warshawsky
ID: 7022656
to Bira:

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

rwarhs

0
 
LVL 6

Expert Comment

by:bira
ID: 7022670
what is the result if you fire   echo $HOST_DOMAIN   ?

what kind of unix do you have ?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 6

Expert Comment

by:bira
ID: 7022735
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
 
LVL 3

Author Comment

by:Ron Warshawsky
ID: 7022755
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
 
LVL 38

Expert Comment

by:yuzh
ID: 7022950
use:
  HOST_DOMAIN=`nslookup \`hostname\` | grep Name
| awk '{print $2}'`

  echo $HOST_DOMAIN

0
 
LVL 3

Author Comment

by:Ron Warshawsky
ID: 7022971

 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
 
LVL 38

Expert Comment

by:yuzh
ID: 7023047
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
 
LVL 3

Author Comment

by:Ron Warshawsky
ID: 7023519

 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
 
LVL 84

Expert Comment

by:ozo
ID: 7023532
HOST_DOMAIN=`/usr/bin/hostname | xargs /usr/sbin/nslookup | grep Name | awk '{print $2}'`
0
 
LVL 3

Author Comment

by:Ron Warshawsky
ID: 7024516

 to ozo:

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

rwarsh
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7025363
HOST_DOMAIN='/usr/sbin/nslookup '"'"'`'"'"'/usr/bin/hostname'"'"'`'"'"'|awk '"'"'/^Name/{print $2}'"'"

rsh host $HOST_DOMAIN
0
 
LVL 3

Author Comment

by:Ron Warshawsky
ID: 7025382

 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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7025509
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
 
LVL 3

Author Comment

by:Ron Warshawsky
ID: 7025523

To ahoffman:

  My UNIX is SunOs 5.8

rwarsh
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7025550
HOST_DOMAIN='/usr/sbin/nslookup `/usr/bin/hostname`|awk '"'"'/^Name/{print $2}'"'"
rsh host $HOST_DOMAIN
0
 

Expert Comment

by:DigitalGuy
ID: 7801973
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
 
LVL 20

Expert Comment

by:jmcg
ID: 10329586
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
 
LVL 20

Expert Comment

by:jmcg
ID: 10329595
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 10332125
may suggestion (http:#7025363) works in ksh
no reason for a refund
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10332673
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
 
LVL 1

Expert Comment

by:Computer101
ID: 10361323
PAQed, with points refunded (100)

Computer101
E-E Admin
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 10361427
Computer101, would you please explain your choice
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 10482583
PAQed - no points refunded (of 100)

Computer101
E-E Admin
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question