1830250 Members
3070 Online
110000 Solutions
New Discussion

script help

 
SOLVED
Go to solution
Nobody's Hero
Valued Contributor

script help

I need help writing a script. I want to check a /var/mail/user file to see if it is empty. If it is , do nothing if it isnt, then I am going to cut some info out of the nmail message and mail it to my cell through telalert. I only need help with the 1st part.

Test
If file is empty
do nothing
if it isnt
do this kind of thing.
UNIX IS GOOD
5 REPLIES 5
RAC_1
Honored Contributor

Re: script help

[ -z /var/mail/file ] || mailx "file not empty" abc@xyz.com

Anil
There is no substitute to HARDWORK
Jean-Luc Oudart
Honored Contributor

Re: script help

if [[ $(wc -l /var/mail/user| cut -f1 -d" ") -eq 0 ]]; then

else

fi

Regards
Jean-Luc
fiat lux
Geoff Wild
Honored Contributor

Re: script help

Have a look at Ian's script(s) in the following post:

http://forums1.itrc.hp.com/service/forums/bizsupport/questionanswer.do?threadId=718563

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Muthukumar_5
Honored Contributor
Solution

Re: script help

We can do effective check as,

if [[ -f filename && ! -s filename ]]
then

echo "File exists with zero length"
# Action to do
fi

We can use ls -s to get file size too,

if [[ -f filename ]]
then

# File exits
if [[ $(ls -s | awk '{ print $1 }') -eq 0 ]]
then

# action to do here.
fi
fi

HTH.
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: script help


[ ! -s /var/mail/file ] || action to do

[ -s /var/mail/file ] && action to do

It also work there.
Easy to suggest when don't know about the problem!