The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Change hostname madmat Linux 3 09-20-2007 07:23 AM
Solaris - unknown hostname - how can I change hostname? XNOR UNIX for Dummies Questions & Answers 1 03-29-2007 07:52 PM
looking up hostname dangral IP Networking 2 10-28-2003 12:56 PM
Printing Problems in unix ... ( Bar-cdoe - Ip Printing) QuickSilver UNIX for Advanced & Expert Users 3 06-04-2002 07:48 AM
Hostname bache_gowda UNIX for Dummies Questions & Answers 1 09-22-2001 01:25 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-28-2008
Registered User
 

Join Date: May 2008
Posts: 2
Printing hostname

Hi,

I am using hostname environment variable in my shell script to print the host name but it's printing nothing.Can you please help me on this.

Please find the part of the code pasted here:

llist=
llist=$(ps -ef | grep -v grep | grep -c "$1")

echo "Hostname is ${hostname}"
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-28-2008
sysgate's Avatar
Unix based
 

Join Date: Nov 2006
Location: /root
Posts: 1,128
From where do you want to extract this hostname value ? You can use simple : localHostName=`hostname`; echo $localHostName
Reply With Quote
  #3 (permalink)  
Old 05-28-2008
joeyg's Avatar
premier etoile de match
 

Join Date: Dec 2007
Location: Home of world champion Boston Celtics
Posts: 533
Wink one approach...

1. assign the return value to a variable
2. send (echo) the variable to screen

Code:
> valhost=$(hostname)
> echo $valhost    
grape
Reply With Quote
  #4 (permalink)  
Old 05-28-2008
Registered User
 

Join Date: May 2008
Posts: 2
Hi,

When I am using commnad:hostname in unix command prompt , it's printing the system name of my system but when I use this command in shell script it gives nothing.

localHostName=hostname
echo $localHostname
Reply With Quote
  #5 (permalink)  
Old 05-28-2008
joeyg's Avatar
premier etoile de match
 

Join Date: Dec 2007
Location: Home of world champion Boston Celtics
Posts: 533
Wink Your command with = is not assigning the value

Try as I show below (ignoring the > as the prompt character):

Quote:
1. assign the return value to a variable
2. send (echo) the variable to screen


Code:
> valhost=$(hostname)
> echo $valhost
grape
Reply With Quote
  #6 (permalink)  
Old 05-28-2008
Registered User
 

Join Date: Jun 2007
Posts: 47
Also u can use the environment variable HOSTNAME.
Reply With Quote
  #7 (permalink)  
Old 05-28-2008
Registered User
 

Join Date: Jun 2007
Posts: 47
Quote:
Originally Posted by gbiswal View Post
Hi,

When I am using commnad:hostname in unix command prompt , it's printing the system name of my system but when I use this command in shell script it gives nothing.

localHostName=hostname
echo $localHostname
Hi,
U can use the environment variable HOSTNAME or
the command hostname <With options such as -a>
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0