Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

shell script for checking

Posted on 2011-03-02
13
Medium Priority
?
374 Views
Last Modified: 2012-05-11
I need a shell script for checking the  particular directory on the server and if there is a core dump file (like core.123 ), it should send an email to me.
I am not sure i will setup a cronjob to execute that shell script every one hour to see the if there are any core dump files, if you have any best practices please let me know.

This shell will run redhat linux 5 server

0
Comment
Question by:wasman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
13 Comments
 
LVL 9

Expert Comment

by:AriMc
ID: 35022690
Try this script, changing the directory name and your e-mail address to appropriate:


#!/bin/sh

if [ -f /tmp/core* ]
then
   echo "Core files exist" | mail -s "Core files exist" myemail@mydomain.com
fi

Open in new window

0
 
LVL 48

Expert Comment

by:Tintin
ID: 35022748
You can't use wildcards in an 'if' test.

#!/bin/bash

if [ -n "$(find /some/dir -type f -maxdepth 1 -name core\*)" ]
then
    echo | mail -s "One or more core files exist"  somebody@example.com
fi

Open in new window


0
 
LVL 9

Expert Comment

by:AriMc
ID: 35022771
Really? It works fine on my Debian.

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 48

Accepted Solution

by:
Tintin earned 2000 total points
ID: 35022996
What Debian version and what shell?

I'm using Debian Squeeze.  Certainly won't work with bash, but will work with ksh, but I would be very surprised if you had overwritten the /bin/sh symlink with /bin/ksh on your system.

$ cat check
if [ -f core* ]
then
   echo matched
fi

Open in new window



$ ls -1
check
core
core.123
core.456
$ sh check
[: 4: core: unexpected operator
$ bash check
check: line 1: [: too many arguments
$ ksh check
matched

Open in new window

0
 
LVL 9

Expert Comment

by:AriMc
ID: 35023112
I'm using Debian Lenny kernel 2.6.26-1-686 and /bin/sh points to the original /bin/bash, see the output below.

Checking the existance of /tmp/core* files with ls:

$ ls -al /tmp/core*
-rw-r--r-- 1 root root 51 2011-03-03 01:40 /tmp/coretemp.txt

Then with a script for non-existing files:

$ cat check
#!/bin/sh

if [ -f /tmp/corez* ]
then
   echo "Yes"
fi

$ ./check
(No output)

Then with the a modified script for existing file:

$ cat check
#!/bin/sh

if [ -f /tmp/core* ]
then
   echo "Yes"
fi

~/tmp$ ./check
Yes








myhost:~/tmp$ uname -a
Linux myhost 2.6.26-1-686 #1 SMP Sat Jan 10 18:29:31 UTC 2009 i686 GNU/Linux

myhost:~/tmp$ ls -al /bin/sh
lrwxrwxrwx 1 root root 4 2009-03-08 20:34 /bin/sh -> bash

myhost:~/tmp$ ls -al /bin/bash
-rwxr-xr-x 1 root root 700492 2008-05-12 22:02 /bin/bash

Open in new window

0
 
LVL 48

Expert Comment

by:Tintin
ID: 35023789
Do a

touch /tmp/core1

and rerun.
0
 

Author Comment

by:wasman
ID: 35024050
Folks thanks a lot for compassion in scripting world,
I forgot to mention one important thing, the script should to be smart enough to know the latest core dump that was produced at last in that directory. Bcz in that directory there will be always some old core dump files exists in that directory.


0
 
LVL 48

Expert Comment

by:Tintin
ID: 35025524
What do you want to do with the latest core file?
0
 

Author Comment

by:wasman
ID: 35027377
the server will be running fine, but sometimes it produces core dump once in a week,
that core dump will make disk out of space and the log don't get written, let's say the core dumps gets produced in /usr/local/web directory, there will be always some
old core dumps will be residing in /usr/local/web directory, for some reason development team want to delete them. So what i want is i will setup a cronjob, that will call
this shell script everyone hour, so the script will check the /usr/local/web directory for any latest core dump files, if they are then it will send email to me and go i delete them or move them.
0
 

Author Comment

by:wasman
ID: 35027399
updated answer

the server will be running fine, but sometimes it produces core dump once in a week,
that core dump will make disk out of space and the log don't get written, let's say the core dumps gets produced in /usr/local/web directory, there will be always some
old core dumps will be residing in /usr/local/web directory, for some reason development team don't want to delete them. So what i want is i will setup a cronjob, that will call
this shell script everyone hour, so the script will check the /usr/local/web directory for any latest core dump files, if there is then it will send email to me and go i delete them or move them.
0
 

Author Comment

by:wasman
ID: 35037292
tintin,

Any updates!!!
0
 

Author Comment

by:wasman
ID: 35057807
not sure why you didn't responded...but i am closing the ticket.. Thanks for helping me out
0
 

Author Closing Comment

by:wasman
ID: 35057815
Thanks for you help
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

715 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