- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- shell script check
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
тАО10-14-2009 06:58 AM
тАО10-14-2009 06:58 AM
The script below is finding orphan files as designed. The only change I need to add is to send me an email only if the system has orphan files right now it sends me an email whether it find an orphan file or not.
#!/usr/bin/sh
typeset -r OSNAME=$( uname -s )
typeset -l HOSTNAME=$( uname -n )
typeset DSTAMP=$(date '+%m-%d-%y %H:%M:%S')
typeset MAILTO="rob.hansen@xxxxxx.com"
case "$OSNAME" in
AIX) print "OS is AIX. Checking for orphan files..."
find / -name "/proc" -prune -o \
\( -fstype jfs -o -fstype jfs2 \) -a \( -nouser -o -nogroup \) -print | xargs ls -ld
;;
SunOS) print "OS is Solaris. Checking for uorphan files..."
find / \( -nouser -o -nogroup \) | xargs ls -ld
;;
esac
cat /tmp/orphan.log | mailx -s "$HOSTNAME $DSTAMP" $MAILTO
return 0
}
Thanks in adnvance.
Solved! Go to Solution.
- Tags:
- find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-14-2009 07:11 AM
тАО10-14-2009 07:11 AM
SolutionRedirect the output of your 'find' command into a file. Then test for the presence of a non-zero size file and send your mail only if the file contains data.
...
find / \( -nouser -o -nogroup \) | xargs ls -ld > /tmp/orphan.log
...
if [ -s /tmp/orphan.log ]; then
cat /tmp/orphan.log | mailx -s "$HOSTNAME $DSTAMP" $MAILTO
fi
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-14-2009 07:11 AM
тАО10-14-2009 07:11 AM
Re: shell script check
Suggest instead of:
cat /tmp/orphan.log | mailx -s "$HOSTNAME $DSTAMP" $MAILTO
Route output to a file.
grep the file for actual orphan files and only if you find something send the email.
send=$(grep
if [ $send -ge 1 ]
then
cat /tmp/orphan.log | mailx -s "$HOSTNAME $DSTAMP" $MAILTO
fi
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-19-2009 09:09 AM
тАО10-19-2009 09:09 AM
Re: shell script check
if [ -s /tmp/orphan.log ]; then
cat /tmp/orphan.log | mailx -s "$HOSTNAME $DSTAMP" $MAILTO
fi
is working fine as expected, however I there are a few generic lines in the output with hashes as shown below:
#+#+# Date and Time: 19 Oct 2009 12:02:07
#+#+# Script: /tmp/orphan.log
#+#+# Submitted by:
Since the hashes are in every file, I need the logic to send an email only when there are files/lines besides the usual hashes.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-19-2009 09:16 AM
тАО10-19-2009 09:16 AM
Re: shell script check
> Since the hashes are in every file, I need the logic to send an email only when there are files/lines besides the usual hashes.
OK, you could use this:
...
FILE=/tmp/orphan.log
STUFF=$(grep -v "#+#+#" ${FILE})
if [ ! -z "${STUFF} ]; then
mailx -s "$HOSTNAME $DSTAMP" $MAILTO < ${STUFF}
Regards!
...JRF...