i've got the following problem:
We've got a shell-script, that creates some different files based on several criteria given, using a sql-script.
After creating, those files are individually zipped and stored, then sent to a ftp-server.
This is all working since 2010, but now they have to be send via e-mail, too.
This wouldn't be a problem, but there are about 40 files created in every run, and so are 40 e-mails sent.
Is it possible to store all the filenames into a variable while they are created in the loop and then zip them into one file, before sending the e-mail?
To be honest, i've never really worked with shell myself and i'm asking a colleague as a favor. I couldn't find a solution via google and this forum seems to be nice
She has to manually sort those e-mails every day, if i can't find a solution...
Thanks in advance!
Edit:
well, i think some of the actual code might help...
This is the important part, only slightly changed
for i in $Criteria; do
FileName="$i"_stuff_`date +'%d%m%Y'`.csv
Subject="$i-stuff `date +'%d.%m.%Y'`"
if [ -s /output/$FileName ]; then
if [ "$P_PASSWORT" != "" ]
then
zip -l -j -P $P_PASSWORT /output/$FileName.zip /output/$FileName
FileName=$FileName.zip
fi
if [ "$P_RECEIVER" != "" ]; then
send_mail "$Sender" "$P_RECEIVER" "$Subjekt" "" /output/$FileName $CommandFileName || { send_mail "$Sender" "$P_ERROR_RECEIVER_MAIL" "$Subjekt" "Error in JOB --> BLA_CUSTOM (FileName: $FileName, stuff: $Criteria). Please Check!"; echo "File couldn't be sent. Error code: $?"; Err_code=1; }
fi
if [ "$P_FTP_SERVER_ID" != "" ]; then
# [internal code for ftp-upload]
fi
fi
done
will create a single archive tarball (A gzipped tape archive) of the 40 files, the files can be listed and individual files can be extracted from the archive or the whole archive un-bundled
If it is in a loop, create a tar archive and use the -r switch to add the other files to the archive file. When done, zip them and send them on their way.
If they are the sole inhabitants of a directory or can be easily specified by a their filenames, just create a tar archive on them directly, zip and mail them...
I didn't expect an answer until tomorrow!
Wow, thanks for the fast reply, i'll read myself into those commands and try to create a test without crashing our system.
Thank you both very much!
Edit:
I tried to modify the example-code from above the way i think would be the easiest (for me).
Am i on the right path?
It's kinda difficould to actually test it, since the script runs only once a day in the early morning and tomorrow i'm at school, so i won't implement it before thursday.
ArchiveName="$Criteria-stuff-`date +'%d.%m.%Y'`"
ArchiveFiles=""
for i in $Criteria; do
FileName="$i"_stuff_`date +'%d%m%Y'`.csv
Subject="$i-stuff `date +'%d.%m.%Y'`"
if [ -s /output/$FileName ]; then
if [ "$P_PASSWORT" != "" ]
then
zip -l -j -P $P_PASSWORT /output/$FileName.zip /output/$FileName
FileName=$FileName.zip
if [ "$P_RECEIVER" != "" ]; then
ArchiveFiles="$ArchiveFiles /output/$FileName"
fi
fi
if [ "$P_FTP_SERVER_ID" != "" ]; then
# [internal code for ftp-upload]
fi
fi
done
if [ "$P_RECEIVER" != "" ]; then
tar -czf $ArchiveName $ArchiveFiles
send_mail "$Sender" "$P_RECEIVER" "$Subjekt" "" /output/$ArchiveName $CommandFileName || { send_mail "$Sender" "$P_ERROR_RECEIVER_MAIL" "$Subjekt" "Error in JOB --> BLA_CUSTOM (FileName: $FileName, stuff: $Criteria). Please Check!"; echo "File couldn't be sent. Error code: $?"; Err_code=1; }
fi