INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

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

(OP)
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

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

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)


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

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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close