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

Shellscript to send an email to group when a file is placed in unix directory: Help needed

Status
Not open for further replies.

surajkrhit

Programmer
Apr 14, 2016
1
IN
Hello Team,

I am new in Shell scripting. In my day today task very often i face a basic problem in which somebody runs some job in uat without notifying others and existing work gets affected and the whole effort in the task gets spoiled.
I want if someone place the file in Unix path(We are using Tectia) then itself one mail will be sent to the group as a notification so that others will get to know who is running what.
Can we achieve this though shell script and can someone guide me to how to do this.
Even Your small help will be appreciated.
Thanks,
Suraj
 
Here's something to get you started:

SENDTO=`tr -s '\n,\r' ', ' < /path/to/file-with-e-mail-addresses-one-per-line.cfg`
Attachment_Content="-a /path/to/attachment-file"
Mail_Trailer_Content="\nThere is a new file.\nAs this is an auto-generated e-mail, please do not reply to this e-mail. \n"
Mail_Content=`echo "${Mail_Trailer_Content}\n"`
echo -e "${Mail_Content}" | mailx -v ${Attachment_Content} -s "NEW FILE DETECTED" ${SENDTO}


==================================
adaptive uber info galaxies (bigger, better, faster, and more adept than cognitive innovative agile big data clouds)


 
Code:
#!/usr/bin/ksh
export PS4='$LINENO#'
sleepsec=${2:-10}
if [ "$1" = "" ]
then
  echo "Err: Need filename as arg"
  exit 12
fi
while [ 1 ]
do
  fn="$1"
  xx=$(ls -l "$fn" 2>&1 )
  xxo="$xx"
  while [ "$xx" = "$xxo" ] || [ ! -f "$fn" ]
  do
    sleep $sleepsec
    xx=$(ls -l "$fn" 2>&1 )
  done
  ls -l "$fn" | mailx -s "$(date) got new $fn" zuser1@zmail.com,suraj@zmail.com
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top