Thanks,
I'll try that.
Main Topics
Browse All TopicsHi,
I'm very new on bash scripting. Please see the attachment, which is check backup and send a success or fail email.
Please help me make it better.
Thanks,
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: simon3270Posted on 2009-11-03 at 09:42:03ID: 25731448
For your grep lines, add
>/dev/null 2>&1
to the end of each to avoid printing the matched line, or add the "-q" option to the last grep command on the line (to stop it printing out the matching line, but only if your grep command supports it)
In your "if" tests for the result of the grep, use:
if [ $? -eq 0 ]
(no quotes needed)
Increment the counter "n" when you fail instead of when you succeed - that way, the test at the end is
if [ $n -eq 0 ]
then
all is OK
else
there was an error
fi
this saves you having to keep $PRDN in step if you add further tests.
Do the "grep $DATE /nsr/logs/donelist.log |grep dxnprdap" command once, and put the output in a temporary file:
grep $DATE /nsr/logs/donelist.log |grep dxnprdap > /tmp/tst.grp
Then check that /tmp/tst.grep file for /usr/ /u01, /u02 etc. Remove the file at the end of the script.
If you do the above, and put the output into /tmp/tst.grp, you can simplify the tests to
if grep -q /u01 /tmp/tst.grep
then
echo /u01 OK
else
echo /u01 failed
let ""n+=1"
fi
(assuming that your "grep" supports the "-q" option to suppress output. If not, add ">/dev/null 2>&1" to the end of the line)