The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 07-03-2009
reddybs reddybs is offline
Registered User
  
 

Join Date: Jan 2009
Location: Sriharikota-AP-India
Posts: 53

Code:
hostname=`grep $client zabbixhosts | cut -f2 -d:`

I tried to simulate your scenario in my linux machine. Assuming that your client variable contains <BaculaServer-fd >.
From the above code, variable hostname contains Server_Bacula if grep is successfull and will contain no value if it fails. Something like this....


Code:
$ cat zabbixhosts
Helpdesk-fd:Server_Helpdesk
Knowledge-fd:Server_Knowledge
BaculaServer-fd:Server_Bacula
Zabbix-fd:Server_Zabbix_1.4.2
 
$ echo $client
sai
 
$  hostname=`grep $client zabbixhosts | cut -f2 -d:` ; echo $hostname
 
$ client="BaculaServer-fd"
 
$ hostname=`grep $client zabbixhosts | cut -f2 -d:` ; echo $hostname
Server_Bacula
 
$ hostname=`grep -w $client zabbixhosts | cut -f2 -d:`; echo $hostname
Server_Bacula