- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: If Then Else Help
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
Discussions
Discussions
Forums
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
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
тАО05-31-2011 10:31 AM
тАО05-31-2011 10:31 AM
I have a script that isn't working and being a noob at this, I need the help of experts.
Below is the script;
#!/bin/sh
MSGTXT="`omnistat |awk '{print $1,$2,$3}'"
echo $MSGTXT
if [$MSGTXT="No currently running"]
then
omnisv stop
sleep 30
cp -p /opt/omni/* /destination
cp -p /var/opt/omni/* /destination
cp -p /etc/opt/omni/* /destination
omnisv start
echo IT WORKS
else
echo SESSION OPEN
fi
Thanks.
J.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2011 10:45 AM
тАО05-31-2011 10:45 AM
SolutionThe second line is mangled. You need matching back-ticks or better yet:
MSGTXT=$(omnistat|awk '{print $1,$2,$3}')
The notation '$( ... )' is modern POSIX syntax or the archaic back-ticks. Both forms execute the enclosed command(s) and collect the output.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2011 10:52 AM
тАО05-31-2011 10:52 AM
Re: If Then Else Help
#!/bin/sh
MSGTXT=$(omnistat|awk '{print $1,$2,$3}')
:echo $MSGTXT
if [$MSGTXT="No currently running"]
then
omnisv stop
sleep 30
cp -p /opt/omni/* /destination
cp -p /var/opt/omni/* /destination
cp -p /etc/opt/omni/* /destination
omnisv start
echo IT WORKS
else
echo SESSION OPEN
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2011 10:58 AM
тАО05-31-2011 10:58 AM
Re: If Then Else Help
> So it should look like;
Well, drop the colon before the word 'echo'. You can do a half-decent syntax check with:
# sh -n filename
...where 'filename' is whatever you call your script. If no output appears, then the script is syntactically correct as far as the shell can determine.
Regards!
...JRF..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2011 11:21 AM
тАО05-31-2011 11:21 AM
Re: If Then Else Help
if [$MSGTXT="No currently running"]
to be
if [ "$MSGTXT" = "No currently running" ]
Close to a quarter-century of experience with HP's shells have taught me to be Very Very Careful when doing string comparisons, so I'm quite liberal with the use of double-quotes to delimit all character strings inside my scripts.
HP-Server-Literate since 1979
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2011 11:25 AM
тАО05-31-2011 11:25 AM
Re: If Then Else Help
I did the sh -n with no errors, however, I keep getting the "SESSION OPEN" even though there isn't any open.
Any ideas?
J.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2011 11:33 AM
тАО05-31-2011 11:33 AM
Re: If Then Else Help
IT WORKS
Thanks all!