- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script question
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2007 04:35 AM
02-19-2007 04:35 AM
script question
+ uname -n
+ [ hosta = hostb ]
I have the if statement in the script for this which is failing :
if [ `uname -n` = hostb ]
then
...
else
# should execute stuff meant for hosta
fi
Its weird in a sense that most of my other scrips are scripted the same way and I even tried having a variable for the uname -n command but it would still equal the wrong box.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2007 05:03 AM
02-19-2007 05:03 AM
Re: script question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2007 05:03 AM
02-19-2007 05:03 AM
Re: script question
if [ `uname -n` = hostb ]
is better written:
if [ $(uname -n) = hostb ]
as the backticks (aka, grave accent) have been deprecated for many years.
As far as a failed match, uname -n reports what it was set to in the startup config file /etc/rc.config.d/netconf. On the machine that is failing, uname has been been set to an unexpected value. Scripting won't fix this because the box is misconfigured. uname -n is *NOT* connected with DNS (see the man page for uname). By convention the Internet name and uname will be the same but there is no restriction to make them different.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2007 05:07 AM
02-19-2007 05:07 AM
Re: script question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2007 05:11 AM
02-19-2007 05:11 AM
Re: script question
In any event, if the situation is as described, the else part should be executing.
Try this (and apply some discplined quoting which you are missing):
if [ "$(uname -n)" = "hostb" ]
then
...
else
...
fi
or better still if using the Korn of POSIX shell:
if [[ "$(uname -n)" = "hostb" ]]
then
...
else
...
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2007 08:22 PM
02-19-2007 08:22 PM
Re: script question
use:
if [[ $(hostname) = hostb ]]
or
if [[ $(uname -n) = hostb ]]
HTH,
Art