- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell Script Quick 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
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
03-08-2004 07:26 AM
03-08-2004 07:26 AM
Would anyone help with this short script as why it is not getting through?
---------------------------------------
The script is to check Oracle listener whether it is up, if not, start it, if yes, exit.
It runs under Oracle, thus lsnrctl can start right there.
****************************
lsnrctl status > /disk3/test/t1
aaa=`grep 'The command completed successfully' /disk3/test/t1`
bbb='The command completed successfully'
ccc='TNS:no listener'
if [$aaa=$bbb]; then
exit
else
if [$aaa=$ccc]; then
lsnrctl start
fi
fi
exit
******************************
Error:
listen_test[6]: [=The: not found.
listen_test[9]: [=TNS:no: not found.
---------------------------------------
Very appreciated.
Steven
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2004 07:30 AM
03-08-2004 07:30 AM
Solutionif [ "$aaa" = "$bbb" ] ; then
exit
else
if [ "$aaa" = "$ccc" ] ; then
lsnrctl start
fi
fi
exit
Note the extra spaces and quotes. What shell are you using for this? If POSIX, do a 'man sh_posix' for information on the syntax for the if statement. It is very syntax dependent.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2004 07:30 AM
03-08-2004 07:30 AM
Re: Shell Script Quick Help
if [ "$aaa" = "$bbb" ] ; then
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2004 07:34 AM
03-08-2004 07:34 AM
Re: Shell Script Quick Help
aaa=$(grep "The command completed successfully" /disk3/test/t1)
It will work exactly the same and is much more readable than using the back-ticks ( ` ).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2004 07:35 AM
03-08-2004 07:35 AM
Re: Shell Script Quick Help
if [$aaa=$bbb]
should be:
if [ "${aaa}" = "${bbb}" ]
then
especialy note the white space after '[' and before ']'. Also, your variables should be protected bu quotes so that null strings don't clobber test.
You will also find this test to be much simpler:
lsnrctl status > tmpfile
grep -q "This command completed sucessfully" tmpfile
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "OK"
else
echo "Bad"
fi
The -q option says only report the status of the grep; 0 = found.
The '[[ ]]' uses the POSIX and Korn shell's internal test whereas '[ ]' spawns the external test command. The internal is more efficient although you can continuey to use the external.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2004 07:36 AM
03-08-2004 07:36 AM
Re: Shell Script Quick Help
So hard to reply first here :-)
As mentioned... you have two troubles.
Double quote the variables, and space around the brackets.
ie...
[ "${aaa} = "${bbb}" ]
...will work just fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2004 07:41 AM
03-08-2004 07:41 AM
Re: Shell Script Quick Help
A typo in the previous post, in my haste to get a response in.
[ "${aaa}" = "${bbb}" ]
missed a doublequote on the previous response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2004 04:13 PM
03-08-2004 04:13 PM
Re: Shell Script Quick Help
Clay's script should be the only one that actually works, even though everyone else has offered you good advice on syntax.
The reason I say this is because you're checking for "The command completed successfully" using grep on a file. Since you're just running a plain grep, you'll *only* get matches. So, $aaa can *never* match $ccc.
Back to Clay's script. All he's doing is checking to see if there was a match and then doing something with that information. And that's all you really need here. Just modify the "OK" and "Bad" results to do whatever you actually want and you should be fine.
Hehe, having said all this, I sure hope I'm not missing something obvious!!!
Regards,
Seth