› Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › Emailing File in Kornshell Script
Thanks,
Ariba
Very simple scrip to send a file.
#!/bin/ksh
mail -s “Subect With Space ”
Thanks for this information. I do already send emails to people to let them know that files are out on their system. I just didn’t know how to attach an actual file to that email. This does look very similar to my email scripts already setup. I didn’t write them, but I definitely can follow them. I know I can do this.
Thanks so much for your help. I will let you know how it goes.
Ariba
Why not use Cloverleaf to perform this task. I’d set up and inbound thread to pick up the file and an outbound thread to route it raw to the downstream system via TCP/IP. If the downstream system can’t open a socket for TCP/IP then I’d opt for FTP instead. I think it’ll be easier to get messages from archived SMAT for support (resend) down the road.
I only use email to send alerts to apps support analysts about their systems but never use it to send files. Also, what if the file is too big…check the size limit on your organization email system.
Sorry I know this is not much help to you. Good luck!
You are correct. I need to check on the file size for this.
I thought I would just set this up as an outbound tcp/ip thread, but when the receiving system said they needed me to email the file to them, I started looking into the emailing thing. One of our network guys actually mentioned that I should be able to write a script to email this file. I’ll double check with him about the email file sizes though.
If I setup the outbound thread as ftp, can I also setup the thread to email the file? I didn’t think that was possible. Maybe I am misunderstanding what you are saying.
Thanks,
Ariba
if { ([file exists $log] == 0) && ([file exists $HciSiteDir/archive/$logname$yesterday.log] == 1)} {
That may be more to what you are looking for.
subject=”$2 – Error Database: $lines lines”
echo “To: me@there.org” > $mailfile
echo “Reply-To: me@there.org” >> $mailfile
echo “CC: me@there.org” >> $mailfile
echo “Subject: $subject” >> $mailfile
echo “” >> $mailfile
echo “ATTENTION CLOVERLEAF DEVELOPERS:” >> $mailfile
echo “” >> $mailfile
echo “Cloverleaf Interface Engine Error DB Results.” >> $mailfile
echo “Please review the following file for more information:” >> $mailfile
echo “=============================================================================” >> $mailfile
echo “The $hcisite error database contains $lines lines, see: $FILEDIR/$today.txt.” >> $mailfile
echo “=============================================================================” >> $mailfile
echo “n” >> $mailfile
echo “This email was generated by: $0” >> $mailfile
/usr/sbin/sendmail -fme@there.org -t < $mailfile >/dev/null
rm $mailfile
-- Max Drown (Infor)
script.pl -f file.txt -s “message subject” someone@somewhere.org <
The “-f” argument is for a file to attach. The standard input to the script will also be included as the body of the message.
#!/usr/local/bin/perl
use Mail::Sender::Easy qw(email);
use vars qw/ %opt /;
use Getopt::Std;
# accept -s as an arg for subject
# accept -f as an arg for file attachment
my $opt_string = ‘f:s:’;
getopts( “$opt_string”, %opt );
#store args in a hash for calling email function
my %args;
#set mail server and From: address
$args{from} = ‘myaddress@medstar.net’;
$args{smtp} = ‘smtp01.medstar.net’;
#read message from stdin
@lines =
$args{’_text’} = join(””, @lines);
#turn on debugging
#$args{debug} = ‘-‘;
#set subject
$args{subject} = “”;
if($opt{s}) {
$args{subject} = $opt{s};
}
if($opt{f}) {
$args{_attachments} = { $opt{f} => { file => $opt{f} } };
}
# process additional args as recipients
$args{to} = “”;
for(@ARGV) {
if ($args{to} eq “”) {
$args{to} = $_;
} else {
$args{to} = $args{to} . “,” . $_;
}
}
email({%args}) or die “email() failed: $@”;
#!/usr/bin/ksh
# ’emailFile’ – email file attachment to Outlook
# usage:
# emailFile {fileName} {emailAddress} [{optional subject}] [{optional body}]
SCRIPTDIR=/hciScripts
SCRATCHDIR=$SCRIPTDIR/tmp
if $# < 2; then
print “nYou need at least 2 parameters: the file name and the email address.nA 3rd parameter, ‘subject text’, is optionalnA 4th parameter, ‘body text’, is optionalnExiting”
exit 1
fi
# get parameters
fileName=$1
emailAddress=$2
if $# > 2; then
subject=$3
else
subject=”Here’s a file for you from Cloverleaf”
fi
if $# > 3; then
bodyText=$4
else
bodyText=”Your file is attached.”
fi
# first convert to DOS delimter format
cp $fileName $fileName.txt
$SCRIPTDIR/unixToDos $fileName.txt
# uuencode the file
/bin/uuencode $fileName.txt $(/bin/basename $1).txt > $SCRATCHDIR/emailAttachment.tmp
cd $SCRATCHDIR
print $bodyText > emailBodyText.tmp
/bin/cat emailBodyText.tmp emailAttachment.tmp > emailData.tmp
/bin/mail -s “$subject” “$emailAddress” < emailData.tmp rm -f emailData.tmp emailBodyText.tmp emailAttachment.tmp cd – 1>/dev/null
rm -f $fileName.txt
exit 0
======================
Here’s the unixToDos script used by the above:
#!/usr/bin/ksh
# ‘unixToDos’- convert from UNIX (0a) to DOS (0d0a) line terminators
# usage: unixToDos {fileName}
# This script converts a file in place
# (in other words, the output file replaces the input file)
# UNIX-style line-feed (hex 0a) end-of-line terminators are changed to
# DOS-style carriage-return line-feed (hex 0d0a) end-of-line terminators
fileName=$1
/hciScripts/bin/perl -i -pe ‘s/n/rn/g’ $fileName
Thanks,
Ariba
#
# SET PATH
#
PATH=/hbo/jaanew:/hbo/jaasav:/usr/bin:/etc:/usr/sbin:/usr/ucb:/home/hci/bin:/usr/bin/X11:/sbin:.:/usr/local/bin:/usr/local/scripts
#echo “jaa_adt_copy”
export PATH
ALL=”
S=”JAA ADT”
#
VALID=`ping -c 1 -q 10.49.56.71 | wc -l`
if [ $VALID -eq 0 ]; then
echo `date +%H:%M` > /tmp/timestamp
mail -s “JAA FTP Transfer Failed” cbrossette@notes_bhs < /tmp/timestamp exit fi echo “open 10.49.56.71” > /tmp/ftptmp.scr
echo “user jaaftp jaa1ftp” >> /tmp/ftptmp.scr
echo “close” >> /tmp/ftptmp.scr
ftp -inv < /tmp/ftptmp.scr > /tmp/ftp_out
FTPSTAT=`grep “Login failed” /tmp/ftp_out | wc -l`
if [ $FTPSTAT -eq 1 ]; then
echo `date +%H:%M` > /tmp/timestamp
mail -s “JAA FTP Login Failed” cbrossette@notes_bhs < /tmp/timestamp exit fi # # copy the file to jaasav # cd /hbo/jaanew JAAFILE=”jaa”`date +%y%m%d`”.txt” JAALINE=`wc -l $JAAFILE` JAALINECNT=`cat $JAAFILE | wc -l` if [ $JAALINECNT -eq 0 ]; then # echo `date +%H:%M` > /tmp/timestamp
# mail -s “JAA No messages” cbrossette@notes_bhs < /tmp/timestamp exit fi NEWFILE=’/hbo/jaanew/mail_jaa’ echo “From: star_root” >$NEWFILE
echo “To: $ALL” >>$NEWFILE
echo “Subject: $S” >>$NEWFILE
echo “MIME-Version: 1.0” >>$NEWFILE
echo ‘Content-Type: Multipart/Mixed; boundary=”~-~-~-~-~”‘ >>$NEWFILE
echo “” >>$NEWFILE
echo “–~-~-~-~-~” >>$NEWFILE
echo “Content-type: Application/text; name=$JAAFILE” >>$NEWFILE
echo “Content-disposition: attachment; filename=`basename $JAAFILE`” >>$NEWFILE
echo “Content-transfer-encoding: 7BIT” >>$NEWFILE
echo “” >>$NEWFILE
cat $JAAFILE >>$NEWFILE
sendmail -t <$NEWFILE rm $NEWFILE # cp $JAAFILE /hbo/jaasav echo “JAA ADT file ( $JAAFILE )has # of lines in file: $JAALINE ” > /tmp/chgmsg
#
#
# ftp the file to the bhs002764
#
echo “open 10.49.56.71” > ftptmp.scr
echo “user jaaftp jaa1ftp” >> ftptmp.scr
echo “put $JAAFILE” >> ftptmp.scr
echo “close” >> ftptmp.scr
ftp -inv < ftptmp.scr > http://ftp.log
rm $JAAFILE
Thanks,
Ariba
I will receive a file via tcp/ip (I previously stated that it would be via ftp, but that changed). I need to make a copy of that file and save in a backup directory with the date stamp. I then need to email this file to multiple email addresses as an attachment. I need to specify a particular subject and also specific information in the body of the email.
I have tried to use a script I received for the email part, but I am having an issue. I also have a kornshell script to put a copy of this file in a backup directory with the date stamp.
I think I have too much going on with this. Is there an easier or simpler way for me to accomplish these two things…1) make a backup copy of the file with a date stamp and 2) email the file as an attachment to multiple addresses?
My inbound thread is a tcp/ip. My outbound thread is fileset-Local.
Here is the error I receive.
Tc[
msgId = message0
proc = ’email_infogen’
args = ”
result = ‘/quovadx/qdx5.2/integrator/sbin/email_infogen.ksh[17]: .txt: not found.
The flags you gave make no sense since you’re not sending mail.’
errorInfo: ‘
/quovadx/qdx5.2/integrator/sbin/email_infogen.ksh[17]: .txt: not found.
The flags you gave make no sense since you’re not sending mail.
while executing
“exec /quovadx/qdx5.2/integrator/sbin/email_infogen.ksh”
(“run” arm line 9)
invoked from within
“switc
This is my email script:
#!/usr/bin/ksh
#list of addresses to send the message to
set emaillist “
#body of the email message
set msg “Please import GAFILE.”
#file to be attached to the email
set filename “LOGAIMPORT.txt”
set tmpfile “/lawson_backup/lawson/infogenesisout/test/$filename”
#unix commands to use
set ux2dos “/usr/bin/ux2dos”
set uuencode “/usr/bin/uuencode”
set mailx “/usr/bin/mailx”
exec $ux2dos $tmpfile | $uuencode $filename.txt | mailx -s “Your file is readyn$msg” $emaillist
Can anyone tell me what is wrong with this script?
Thanks in advance.
Ariba Jones
I have a similar set-up, but I use UPoC in the outbound thread. How are you calling your shell script?
Gary
set mailx “/usr/bin/mailx”
So don’t you need to put a dollar sign, $, in front of “mailx” in your exec line like this?:
exec $ux2dos $tmpfile | $uuencode $filename.txt | $mailx -s “Your file is readyn$msg” $emaillist
I call my shell script (to make a backup copy of the file) through a crontab entry. I have my email script setup as a kornshell script that gets called in a tcl. I have this tcl attached to the Outbound tab of my outbound thread on the TPS Outbound Data field.
I have a feeling I have too much going on here. I think I just need to start over with this logic completely.
Are you doing something like this on your end?
Thanks,
Ariba
I made the change that you suggested and now I get a different error when my script runs.
Tcl error:
msgId = message0
proc = ’email_infogen’
args = ”
result = ‘/quovadx/qdx5.2/integrator/sbin/email_infogen.ksh[17]: .txt: not found.
/quovadx/qdx5.2/integrator/sbin/email_infogen.ksh[17]: -s: not found.’
errorInfo: ‘
/quovadx/qdx5.2/integrator/sbin/email_infogen.ksh[17]: .txt: not found.
/quovadx/qdx5.2/integrator/sbin/email_infogen.ksh[17]: -s: not found.
while executing
“exec /quovadx/qdx5.2/integrator/sbin/email_infogen.ksh”
(“run” arm line 9)
invoked from
I think I need to possibly abandon this script and try a different approach (and/or script). I just don’t know where to go from here.
Thanks,
Ariba
The major problem is that you are using tcl syntax to write a ksh script. The two languages are not interchangeable.
The error message gives you a clue:
result = ‘/quovadx/qdx5.2/integrator/sbin/email_infogen.ksh[17]: .txt: not found
It says “.txt” is not found.
Your only reference to “.txt” is “$filename.txt”.
“set” under ksh does not do what you think it does.
filename does not exist as a variable.
However, this would probably work if you changed the beginning of the script to run under tcl rather than ksh.
Thanks,
Ariba
#!/usr/bin/ksh
Change it to something like this:
#!/qdx/qdx5.2/integrator/bin/tcl
Of course, the root path may be different on your site.
Hope this helps…
Tom Rioux