Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search for file, if not there email to mult people

Status
Not open for further replies.

njdnjd

MIS
Jan 21, 2002
8
US
Hello Fellow Scripters,
I am a novice at this so any help is greatly appreciated. I need to create a shell script that will check a directory for a file (call it Archive) and if it is NOT there with todays date send an email to 3 people with a message Ex. "Someone is sleeping on the job". I will set a crontab to check this daily which I can do. It's just the find and IF NOT there Send part.
Thanks for any help.

njdnjd
 
# Check to see if we got any myfiles*.txt files...

if [ `grep -c "myfiles" $DIRLIST` -eq 0 ]; then
mail -s &quot;no myfiles.txt files&quot; $SYSADMIN << END

Is that what you want?
 
-------------------------------------------
#!/bin/ksh

FILE=(full-path-to-your-file)
DATE=`date '+%b %d'`
ls $FILE | grep &quot;$DATE&quot; || mailx -s&quot;someone is sleeping on the job&quot; &quot;(all mail recipients separated by spaces)&quot;<(some file with the message you want to mail in it)

---------------------------------------------
anything in () is what you need to customize. there's probably a better way, but this should work fine for you.
 
Hi,

Firstly . do you want to mail users on there external address i.e. fred@gungoo.com (externally to PC's)
or will it be locally which have several user id's ?

If externally , do you have a mail server which will forward the mails . If so this needs to be set up first
and tested , the rest will be fairly simple .

E.g. the following will send mail to external users ,via
an mail server which is an NT server ,

If you search this forum for mail users or something similar you'll see loads of threads about setting up sendmail to mail users .

MSG=&quot;someone is sleeping on the job&quot;
if [[ !-f /dir/archive ]];
then
cat << EOD | /usr/sbin/sendmail maillist
From: root@$(hostname).yourdomain
Subject: Wake up on $(hostname)
${MSG}
EOD
fi


maillist is an alias set in sendmail which is a group containing the email addresses of the users.

HTH
 
Thanks I will try them and get back to you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top