- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: grep in script
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
01-26-2004 09:16 AM
01-26-2004 09:16 AM
But I am having problems setting the script up.
if [ -f $BACKUP_LOG ]
then
if [ `grep -i` '"already exits" | "parameter not set" | "find: cannot get"
| "not found" | "No such file or directory" | "grep:"
| "WARNING" | "FAILED" | "Permission denied"' $BACKUP_LOG ]
then
$MAIL -s "$SUBJECT" $MAILTO < $BACKUP_LOG
fi
fi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 09:21 AM
01-26-2004 09:21 AM
Re: grep in script
I am not able to test but I think that if you replace the grep whit an egrep you are close.
Gideon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 09:22 AM
01-26-2004 09:22 AM
Re: grep in script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 09:26 AM
01-26-2004 09:26 AM
Re: grep in script
If you would like to grep multiple lines, then you would need to use "-E", extended regular expressions. For ex.,
grep -E -i 'already exists|parameter not set' $BACKUP_LOG
etc
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 09:28 AM
01-26-2004 09:28 AM
Re: grep in script
Sorrie but i can not this but:
....
if [ `egrep -qi 'already exits" | "parameter not set" | "find: cannot get"
| "not found" | "No such file or directory" | "grep:"
| "WARNING" | "FAILED" | "Permission denied"'` ] then
....
etc
Gideon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 09:29 AM
01-26-2004 09:29 AM
Re: grep in script
if [ `grep -i` '"..."|"..."' file ...
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] -e pattern_list...
[-f pattern_file...] [file...]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 09:30 AM
01-26-2004 09:30 AM
Re: grep in script
if [ -f $BACKUP_LOG ]
then
VAR1=$(grep -q -i -e "already exists" -e "parameter not set" -e "find: cannot get" -e "not found" -e "No such file or directory" -e "grep:" -e "WARNING" -e "FAILED" -e "Permission Denied" $BACKUP_LOG)
if [ $? = 0 ]
then
$MAIL -s "$SUBJECT" $MAILTO < $BACKUP_LOG
fi
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 09:30 AM
01-26-2004 09:30 AM
Solutionif [[ -f ${BACKUP_LOG} ]]
then
grep -i -E -q -e "already exits" -e "parameter not set" -e "find: cannot get"
-e "not found" -e "No such file or directory" -e "grep:"
-e "WARNING" -e "FAILED" -e "Permission denied" ${BACKUP_LOG}
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
${MAIL} -s "${SUBJECT}" ${MAILTO} < ${BACKUP_LOG}
fi
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 09:49 AM
01-26-2004 09:49 AM
Re: grep in script
BACKUP_LOG=/tmp/filename
if [ -f $BACKUP_LOG ]; then
grep -i "already exists"|"parameter not set"|"find:cannot get"|"WARNING"| $BACKUP_LOG
if {$? = 0 ]; then
SUBJECT="Error found"
email="admin@test.com"
mailx -s"$SUBJECT" $email<
EOF
Let us know if this helps..
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 09:53 AM
01-26-2004 09:53 AM
Re: grep in script
But now I get an error...
/home/ac/scripts/backup/d2t_archbu.sh[54]: -e: not found.
/home/ac/scripts/backup/d2t_archbu.sh[55]: -e: not found.
if [[ -f $BACKUP_LOG ]]
then
grep -i -E -q -e "already exits" -e "parameter not set" -e "find: cannot get"
-e "not found" -e "No such file or directory" -e "grep:"
-e "WARNING" -e "FAILED" -e "Permission denied" $BACKUP_LOG
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
$MAIL -s "$SUBJECT" $MAILTO < $BACKUP_LOG
fi
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 09:55 AM
01-26-2004 09:55 AM
Re: grep in script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 10:00 AM
01-26-2004 10:00 AM
Re: grep in script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 10:00 AM
01-26-2004 10:00 AM
Re: grep in script
#!/usr/bin/sh
if [ -f $BACKUP_LOG ]; then
cat >grep.pat <
parameter not set
find: cannot get
not found
No such file or directory
grep:
WARNING
FAILED
Permission denied
EOG
if [ `grep -i -f grep.pat $BACKUP_LOG` ]; then
$MAIL -s "$SUBJECT" $MAILTO < $BACKUP_LOG
fi
rm grep.pat
fi
Easy to read, easy to maintain, easy to extend
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 10:04 AM
01-26-2004 10:04 AM
Re: grep in script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 10:15 AM
01-26-2004 10:15 AM
Re: grep in script
$cat data
already exist bla bla
parameter not set yada yada
find: cannot get this is a test line
No such file or directory ofcourse there is no such file or directory
$grep -E -i 'already exist|parameter not set|find: cannot' data
already exist bla bla
parameter not set yada yada
find: cannot get this is a test line
So, it should have worked if you put everything in one line as mentioned by others.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 10:31 AM
01-26-2004 10:31 AM
Re: grep in script
if [ grep -i
-e "already exits" \
-e "parameter not set" \
-e "find: cannot get" \
-e "not found" \
-e "No such file or directory" \
-e "grep:" \
-e "WARNING" \
-e "FAILED" \
-e "Permission denied" \
$BACKUP_LOG ]
then
...
fi
Note that -E (or egrep) brings a lot of extra parsing code into play for extended regular expressions. Usually the -e approach is faster and easier to read. You might want to change the words WARNING and FAILED to WARN and FAIL so grep will pickup both forms. And I would add ERROR and CRITICAL to your list just in case.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2004 10:33 AM
01-26-2004 10:33 AM
Re: grep in script
Bill Hassell, sysadmin