Printing hostname


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Printing hostname
# 1  
Old 05-28-2008
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}"
# 2  
Old 05-28-2008
From where do you want to extract this hostname value ? You can use simple : localHostName=`hostname`; echo $localHostName
# 3  
Old 05-28-2008
Hammer & Screwdriver one approach...

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

Code:
> valhost=$(hostname)
> echo $valhost    
grape

# 4  
Old 05-28-2008
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
# 5  
Old 05-28-2008
Hammer & Screwdriver 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
# 6  
Old 05-29-2008
Also u can use the environment variable HOSTNAME.
# 7  
Old 05-29-2008
Quote:
Originally Posted by gbiswal
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>
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Printing, SYSPRINTER, IP printing

Dear readers, We have a printer problem with a UNIX system. The OS is Unix IRIX 6.5 We have connected a printerto the system. If we then make a test print everything goes well . (IP printing) But if we make a print from the "orrga,i"program. Then we see all the printouts stuck within the... (3 Replies)
Discussion started by: SergevdH
3 Replies

2. UNIX for Advanced & Expert Users

Hostname -f hostname: Unknown host

deleted (0 Replies)
Discussion started by: hce
0 Replies

3. Emergency UNIX and Linux Support

HP UX - ILO Console hostname different than Machine Hostname...

Hi All, So we added a new HP-UX 11.31 machine. Copied OS via Ignite-UX (DVD)over from this machine called machine_a. It was supposed to be named machine_c. And it is when you log in...however when I'm in the ILO console before logging in, it says: It should say: What gives? And how do... (4 Replies)
Discussion started by: zixzix01
4 Replies

4. UNIX for Dummies Questions & Answers

Sco Unix printing : jobs hangs in queue - printing via lp versus hpnpf

Hi, We have a Unix 3.2v5.0.5. I installed a printer via scoadmin, HP network printer manager with network peripheral name (hostname and ipadres are in /etc/hosts). This is the configuration file : Code: root@sco1 # cat configurationBanner: on:AlwaysContent types: simpleDevice:... (0 Replies)
Discussion started by: haezeban
0 Replies

5. Windows & DOS: Issues & Discussions

Linux to Windows Printing: PDF starts printing from middle of page.

We are using Red Hat. We have a issue like this: We want to print from Linux, to a printer attached to a Windows machine. What we want to print is a PDF. It prints, but the printing starts from the middle of the page. In the report, there is no space at the top but still printing starts from the... (5 Replies)
Discussion started by: rohan69
5 Replies

6. UNIX for Dummies Questions & Answers

Solaris - unknown hostname - how can I change hostname?

Hello, I am new to Solaris. I am using stand alone Solaris 10.0 for test/study purpose and connecting to internet via an ADSL modem which has DHCP server. My Solaris is working on VMWare within winXP. My WinXP and Solaris connects to internet by the same ADSL modem via its DHCP at the same... (1 Reply)
Discussion started by: XNOR
1 Replies

7. IP Networking

looking up hostname

Using Solaris 8 (or WINXP). I am trying to look up a specific DNS hostname, but I don't know which DNS server houses that entry. How can I find the hostname? nslookup gives me the following: C:\>nslookup hostname Server: dnsserver Address: x.x.x.x *** dnsserver can't find hostname:... (2 Replies)
Discussion started by: dangral
2 Replies

8. UNIX for Dummies Questions & Answers

hostname in linux

Hi i am using the Kde graphic interface, and what to know how you set the hostname in linux, what do i click? Ok thanx (6 Replies)
Discussion started by: matt2kjones
6 Replies

9. UNIX for Advanced & Expert Users

Printing Problems in unix ... ( Bar-cdoe - Ip Printing)

Hi guys ... i need ur help with some printing problem in unix ... first prob. : i wanna print from my NCR unix to an Win NT , Ip based printing server ( HP JetDirect ) . My issue , is it possible to print directly to an Ip address from unix ? How do i make it work to get any results ?... (3 Replies)
Discussion started by: QuickSilver
3 Replies

10. UNIX for Dummies Questions & Answers

Hostname

Hello, I am installing redhat linux 6.2 on an intel based system. Whether i want to know any naming conventions should i follow. ie Any convention to follow to name a linux machine(To give hostname). Simillarly for domain name also. Please suggest in this regard (1 Reply)
Discussion started by: bache_gowda
1 Replies
Login or Register to Ask a Question