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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

email script

Status
Not open for further replies.

unixkid

IS-IT--Management
May 22, 2001
105
US
Newbie in need of help...
Need to write a script to do the following:

1. cd to /opt/outbound
2. mailx all files as attachments to testguy@domain.com
3. move files just emailed to /opt/sent
4. log any issues

I have ben trying to wite a simple shell script but things are not working heeeelllpppp
 
I didn't get any responses but I figured out the code. Hope this will help someone else:

DIR=/home/user/scripts/add*
EMAIL="user@domainname.com"
LOGFILE=/usr/logs/file_check.log

# If the STRING is NOT zero email a message that there are files
# is this directory.
# Or if you wish you can email the file

if [[ ! -z `ls ${DIR}` ]]
then
print "Files exist" > ${LOGFILE}
ls ${DIR} | while read name
do
print "File ${name} mailed to ${EMAIL} >> ${LOGFILE}
email -s &quot;Files from home&quot; ${EMAIL} < ${name}
done
else
print &quot;No Files exist&quot; >> ${LOGFILE}
exit
fi

# Continue with any thing else you wish
# Do you need to log information check above
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top