?
Solved

Unix shell script question to add email if deleting more than 20 directories

Posted on 2007-07-30
11
Medium Priority
?
299 Views
Last Modified: 2013-12-26
Hi,

I have a shell script that deletes core dump directories under OH/bdump directory but I want to add 1 more thing to the script and that is to send and an email when it deletes more than 20 directories.
Can anyone please help me ASAP.  I am using the find command to delete the directories.

Thanks in advance!!!
0
Comment
Question by:issa7860
  • 6
  • 5
11 Comments
 
LVL 58

Expert Comment

by:amit_g
ID: 19594690
Show us what you are doing now so that the minimum changes can be suggested.
0
 

Author Comment

by:issa7860
ID: 19594791
The following is the script that deletes the directories:

delete()
{
  export ORAENV_ASK=NO
  export ORACLE_SID=$INSTANCE_NAME

  . oraenv

find $ORACLE_BASE/admin/$ORACLE_SID/bdump -name "cdmp_*"  -mtime +1 -exec rm -rf {} \;
}

and I want to add email if the directories deleted are more than 20.  The email has be before the deletion.
0
 
LVL 58

Expert Comment

by:amit_g
ID: 19594851
delete()
{
  export ORAENV_ASK=NO
  export ORACLE_SID=$INSTANCE_NAME

  . oraenv

  find $ORACLE_BASE/admin/$ORACLE_SID/bdump -name "cdmp_*"  -mtime +1 -exec echo "rm -rf " {} \; > /tmp/DeleteFileTemp.$$
  fileCount=`wc < /tmp/DeleteFileTemp.$$`

  if [ $fileCount -gt 20 ]
  then
     cat /tmp/DeleteFileTemp.$$ | mail -s "More then 20 files being deleted"  WhateverUser@WhateverDomain.com
  fi

  cat /tmp/DeleteFileTemp.$$ | sh
  rm /tmp/DeleteFileTemp.$$
}
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:issa7860
ID: 19602177
Thanks. I used your script and it's deleting the files but getting the following error on unix command line after executing the script also not getting any emails:

purge[11]: 123: unknown test operator

and the script is:

delete()
{
  export ORAENV_ASK=NO
  export ORACLE_SID=$INSTANCE_NAME

  . oraenv

find $ORACLE_BASE/admin/$ORACLE_SID/issa -name "cdmp_*"  -mtime +1 -exec echo  "rm -rf" {} \; > /tmp/DeleteFileTemp.$$

  fileCount=`wc < /tmp/DeleteFileTemp.$$`

  if [ $fileCount -gt 20 ]
  then
     cat /tmp/DeleteFileTemp.$$ | mailx -s "${ORACLE_SID} on ${SERVER} More then 20 directories being deleted." username@domain.com
  fi

  cat /tmp/DeleteFileTemp.$$ | sh
  rm /tmp/DeleteFileTemp.$$
}
0
 
LVL 58

Expert Comment

by:amit_g
ID: 19602951
Oh I missed a flag in wc. Change

fileCount=`wc < /tmp/DeleteFileTemp.$$`

to

fileCount=`wc -l < /tmp/DeleteFileTemp.$$`
0
 

Author Comment

by:issa7860
ID: 19603278
I did the change and now I am getting the following error:
purge[10]: 41:  not found

and no email yet?  the "cdmp_*" are directories.  Please let me know.

Thanks.
0
 

Author Comment

by:issa7860
ID: 19603641
Looks like the count was 41 but then why it did not execute the next line and send the email.  The lines in the file is 41.  Please let me know ASAP.  Thanks.
0
 
LVL 58

Expert Comment

by:amit_g
ID: 19603725
What shell are you using? Add

set -x

fileCount=`wc -l < /tmp/DeleteFileTemp.$$`

and run it again. What messages do you see on the screen?
0
 

Author Comment

by:issa7860
ID: 19604297
I am using KSH and got the following after running the script:

+ + wc -l
+ 0< /tmp/DeleteFileTemp.945
fileCount=      41
+ 41 -gt 20
/dba/bin/purge[11]: 41:  not found
+ sh
+ cat /tmp/DeleteFileTemp.945
+ rm /tmp/DeleteFileTemp.945
0
 
LVL 58

Accepted Solution

by:
amit_g earned 500 total points
ID: 19604325
Change

if [ $fileCount -gt 20 ]

to

if [[ $fileCount -gt 20 ]]
0
 

Author Comment

by:issa7860
ID: 19604625
Thanks the extra square parenthesis did the trick.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question