- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: If then statement 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
Forums
Discussions
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
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
06-10-2004 09:20 AM
06-10-2004 09:20 AM
If then statement help
if [ 'cat /export/home/mduru/vxdisk.list|grep oracle' > /dev/null ]
then mailx -s "unix mail test" melduru@yahoo.com st
else echo "no listing"
fi;
Thanks
Mel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2004 09:29 AM
06-10-2004 09:29 AM
Re: If then statement help
COUNT=$(grep -c oracle /export/home/mduru/vxdisk.list)
if [ "${COUNT}" > 0 ] ; then
mailx -s "unix mail test" melduru@yahoo.com else
echo "nno listing"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2004 09:33 AM
06-10-2004 09:33 AM
Re: If then statement help
1. Getting the return value of the previous command and testing it for success.
grep -q oracle /export/home/mduru/vxdisk.list
RESP=$?
if [ $RESP = 0 ]
then
mailx -s ....
else
echo "no listing"
fi
2. Directly testing the command with if
if grep -q oracle /export/home/mduru/vxdisk.list
then
mailx -s ...
else
echo "no listing"
fi
There are few other ways. I like the first way as it is more readable to me.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2004 09:34 AM
06-10-2004 09:34 AM
Re: If then statement help
COUNT=$(grep -c oracle /export/home/mduru/vxdisk.list)
if (( ${COUNT} > 0 )) ; then
mailx -s "unix mail test" melduru@yahoo.com else
echo "nno listing"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2004 09:40 AM
06-10-2004 09:40 AM
Re: If then statement help
count=`grep -q oracle $FILE | wc -l`
if [ $count -gt 0 ]
then
mailx -s "unix mail test" melduru@yahoo.com < $FILE
else
echo "Nothing found to mail"
fi
hope this helps
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2004 10:00 AM
06-10-2004 10:00 AM
Re: If then statement help
Regards,
Mel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2004 01:35 PM
06-10-2004 01:35 PM
Re: If then statement help
For readability (and to avoid using an obsolete and deprecated shell constructs, the grave accents), here's a simpler version:
MYFILE=/export/home/mduru/vxdisk.list
if $(grep -q $MYFILE)
then
mailx -s "stuff.." me@yahoo.com < $MYFILE
else
echo "no listing"
fi
See man sh-posix or man ksh concerning grave accents. Note that $(...) is also faxable whereas grave accents are almost always lost or copied incorrectly.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2004 03:25 PM
06-10-2004 03:25 PM
Re: If then statement help
If you are really interested in one line, you can actually use
grep -q oracle /export/home/mduru/vxdisk.list && mailx -s "unix mail test" melduru@yahoo.com < /export/home/mduru/vxdisk.list
Looking at /export structure, I feel yours is a SUN/Solaris system. grep -q is equivalent to " > /dev/null 2>&1".
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2004 05:21 AM
06-11-2004 05:21 AM
Re: If then statement help
Regards,
Mel