shell script for checking

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

wasmanAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
TintinConnect With a Mentor Commented:
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
 
AriMcCommented:
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
 
TintinCommented:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
AriMcCommented:
Really? It works fine on my Debian.

0
 
AriMcCommented:
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
 
TintinCommented:
Do a

touch /tmp/core1

and rerun.
0
 
wasmanAuthor Commented:
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
 
TintinCommented:
What do you want to do with the latest core file?
0
 
wasmanAuthor Commented:
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
 
wasmanAuthor Commented:
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
 
wasmanAuthor Commented:
tintin,

Any updates!!!
0
 
wasmanAuthor Commented:
not sure why you didn't responded...but i am closing the ticket.. Thanks for helping me out
0
 
wasmanAuthor Commented:
Thanks for you help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.