Check Error File attach and email zip file


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Check Error File attach and email zip file
# 1  
Old 02-19-2019
Check Error File attach and email zip file

I need something to say if these two file extensions exist in this directory *err and *rpt
zip up these files into one zip file and email them to me.

If they don't exist wait 2 hours and check again.... Not sure how to determine if I need to do an if then statement or a while true or a for loop.

If files exist, then do these commands..... sorry still a novice here.

Code:
 
for file in $optfiles; do
       find  $optfiles  | grep -P '\.rpt|\.err' | tar -cvzf optumerrors.gz -T - ;
       find -f $optfiles/*gz -exec mail -a $optfiles/*.gz -s "Op Error Files" jdaw@321example.com < /dev/null {} \;
       rm -f $optfiles/'\*err|\*rpt' ;
       mv *gz $optfiles/backup/ ;
done

# 2  
Old 02-20-2019
Sorry but there are a few clarifications necessary:

First, please tell us on which OS(es) this is supposed to run, which shell you want to use (optionally which version of these), etc..

Second:
Quote:
Originally Posted by xgringo
I need something to say if these two file extensions exist in this directory *err and *rpt
zip up these files into one zip file and email them to me.
Do you mean you need to initiate said action when both an *.err and a *.rpt file are present or if any of these is present?

Quote:
Originally Posted by xgringo
If they don't exist wait 2 hours and check again.... Not sure how to determine if I need to do an if then statement or a while true or a for loop.
This is easy to answer: neither one. Put the final script, which just checks once, into crontab and let cron take care of calling it every two hours. That, after all, is what it was designed for.

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to attach a .txt file or .log file to mail and mailx command

Hi, I am trying to attach a .log file or .txt file to mail command to send an email once my ksh script executed. I am unable to use mutt command as it has been not installed and i am not supposed to install it. I have tried many ways by googling which has not helped me to succeed. Here is my... (5 Replies)
Discussion started by: Samah
5 Replies

2. Shell Programming and Scripting

need to zip 2 GB file and send it via email

i want to zip the 2GB file and send it via email from unix machine using uuencode. could you please suggest whether it will possible or not and also command to do it. (3 Replies)
Discussion started by: mail2sant
3 Replies

3. Shell Programming and Scripting

How to split a csv file and zip it and attach using mutt command?

We need to redirect the output of a query to .csv file each containing a specified number of lines.Then we should zip these files and send as attachment using mutt command. We tried using split -l 500 query_output.txt outputfile Since we are not sure about the exact number of files... (0 Replies)
Discussion started by: Jassz
0 Replies

4. UNIX for Advanced & Expert Users

Zip an excel file and email using script.

Hi All, Currently i am using below script to attach excel and email from a Unix script. uuencode ASC.xls|mailx -m -s "ABCD_subject`TZ=CST+24 date +%d-%b-%y`" email@email.com Can anyone give me or help me in zipping excel and sending that email as the excel is very heavy. Thanks, (14 Replies)
Discussion started by: Nithin
14 Replies

5. Shell Programming and Scripting

Attach a binary file to email in a script

Hi, I am trying to get an email sent out by the unix ( aix ) system that has a .gz file attached to it. I can get the attachment, but it's not working when being looked at from outlook. I think there is a problem because of the way I am doing it, and the fact that it's binary. I am trying to... (15 Replies)
Discussion started by: fwellers
15 Replies

6. UNIX for Dummies Questions & Answers

How to attach a file in a email

Anyone can help me, in Unix, how can I attach a file in the email? Thank (3 Replies)
Discussion started by: ting123
3 Replies

7. Shell Programming and Scripting

attach multiple file in an email

Hello I have to attach multiple file as an email attachment. here is what i my understanding so far: 1. search in a certain directory that is there any specific file say for example .xml file exist or not 2. if exist then take those file name from the folder and attach it to another text... (1 Reply)
Discussion started by: osrukarigor
1 Replies

8. UNIX for Dummies Questions & Answers

How to use "mail" to attach a file with an email?

echo "content" | mail email@address -s subject Where to attach a file with the email? (2 Replies)
Discussion started by: meili100
2 Replies

9. UNIX for Dummies Questions & Answers

zip and email a file

I am trying to zip and email a .csv file from my unix box to myself and I get corrupt file. I have used the gzip to zip the file and I am using Winzip to try to unzip it. I'm not sure what I am doing wrong. Should I be using the zip command? (4 Replies)
Discussion started by: spalmarez
4 Replies

10. Shell Programming and Scripting

check if exists a .ZIP file and unzip it using ftp

hi this is my question i have my script what have to verify the existence of a .ZIP file in a extern server (using ftp). if there are .ZIP files, the idea is what the script "unzip" them in the specified folder. THE PROBLEM IS what the script doen´t unzip the .ZIP files, and besides, delete... (1 Reply)
Discussion started by: DebianJ
1 Replies
Login or Register to Ask a Question