- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script wanted
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-22-2007 10:32 PM
тАО10-22-2007 10:32 PM
I am not familiar with writing script , if I want to check a directory , to find out all the file that the files are
1. contains a word "shutdown" ( any Block or small letter ) ,
2. not elder than 3 days ,
then send mail with the file name and the whole phase of the shutdown statement .
can advise how to write the script .
thx in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-22-2007 11:33 PM
тАО10-22-2007 11:33 PM
Re: script wanted
set -u
export PATH=/usr/bin
MYDIR=/changeMEtoYOURdir
cd $MYDIR
RTN=$?
[ $RTN -ne 0 ] && echo "no permission or no such directory: $MYDIR" && exit 1
FILELIST=$(find * -type f -prune -mtime -3)
[ -z "$FILELIST" ] && echo "no files less than 4 days old" && exit 2
SDLIST=$(grep -i shutdown $FILELIST)
COUNT=$(echo "$SDLIST" | wc -l)
[ $COUNT -eq 0 ] && SDLIST="none found"
[ $COUNT -eq 1 ] && SDLIST=$FILELIST:$SDLIST
echo "$SDLIST" | mailx -s "$COUNT file(s) found with shutdown" your_name@cpu.com
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-22-2007 11:46 PM
тАО10-22-2007 11:46 PM
Solutioni think its not very comlicated. I wrote a simple shell script that you can try.
#!/bin/sh
PATH=searching_path
N=number_of_days
TEXT=word_you_are_searching
FILE=file_where_you_writing results
EMAIL=email_address_where_you_send_results
find $PATH -type f -ctime -$N | xargs grep -i $TEXT > $FILE
mail -s "SUBJECT" $EMAIL < $FILE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-23-2007 07:05 AM
тАО10-23-2007 07:05 AM
Re: script wanted
#!/bin/sh
PATH="/bin:/usr/bin"
MYDIR="/directory/you/want/to/scan"
# make sure we have the directory
if [ -d $MYDIR ] ; then
cd $MYDIR
if [ $? -ne 0 ] ; then
echo "could not cd to $MYDIR" ; exit 11
fi
else
echo "no such directory $MYDIR" ; exit 2
fi
# make a list of files
FILES=`find . -mtime -3 -type f -print 2>>/dev/null |grep -i shutdown`
# Do nothing if we have nothing
if [ "${FILES}x" = "x" ] ; then
echo "No files to process"
else
TMP="/tmp/my.mailfile.txt"
for FILE in $FILES ; do
echo "$FILE" >>$TMP
cat $FILE >>$TMP
echo "" >>$TMP ; echo "" >>$TMP
done
cat $TMP |mailx -s "shutdown requests" youraddr@somewhere.net
rm $TMP
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-24-2007 10:29 PM
тАО10-24-2007 10:29 PM
Re: script wanted
If I want the mail is only send when the word "error" is exist , that mean if no error then don't send the mail , can advise what can i do ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-25-2007 12:17 AM
тАО10-25-2007 12:17 AM
Re: script wanted
change the 'else' part of Shannon├Г s solution to:
...
else
TMP="/tmp/my.mailfile.txt"
SEARCH4=error
for FILE in $FILES ; do
if fgrep $SEARCH4 $FILE >/dev/null
then
print "\n$FILE"
print "================="
cat $FILE
fi
done >$TMP
if [ -s $TMP ]
then
mailx -s "shutdown requests" youraddr@somewhere.net <$TMP
fi
rm $TMP
fi
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-25-2007 03:11 PM
тАО10-25-2007 03:11 PM
Re: script wanted
My script is simple as below , it works find now ..
find /ora/output/ -type f -mtime -2 | xargs grep -i "error" > $FILE
cat $FILE >> $mailfile
echo "System checking" >> $mailfile
mail -f "admin@my.com" -s "System Checking" user@my.com < $mailfile
Now , I would like to have a more request
1. I will run this script three times a day , so user will receive the same error statement six times even they have fixed the error , I would like if the error statement has already sent to the user , then it will NOT send the same error statement again , that means user will receive the same error statement one time only ;
2. if no error then don't send the mail to user
can advise what can I do ? Thx in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-25-2007 08:04 PM
тАО10-25-2007 08:04 PM
Re: script wanted
regarding 2)
I gave already a solution:
...
done >$TMP
if [ -s $TMP ]
then
mailx -s "shutdown requests" youraddr@somewhere.net <$TMP
fi
...
reagarding 1)
Simplest solution: keep the last result and compare against this:
...
done >$TMP
if [ -s $TMP ]
then
if [ -s $TMP.last ] && cmp -s $TMP $TMP.lst
then rm $TMP
else
mailx -s "shutdown requests" youraddr@somewhere.net <$TMP
mv $TMP $TMP.last
fi
else rm $TMP
fi
mfG Peter