1847242 Members
3014 Online
110263 Solutions
New Discussion

Script / mail attachment

 
Junior C.
Frequent Advisor

Script / mail attachment

Our customer send us data daily attach to e-mail. Attach files come in the following format zip, tar etc. Someone check for mail then unzip etc attachment.

I'm looking for a script that will check mail attachment an unzip or untar depending on attachment format.

thanks,
1 REPLY 1
Anthony deRito
Respected Contributor

Re: Script / mail attachment

Junior,

Not sure what you are trying to accomplish here but are you talking about receiving attachment files and storing them on UNIX then determining how to unpack the files. If you are, you can store the file list in a UNIX file. Use this UNIX file as an input control file to a while loop and process each entry in a loop. Within the loop, run the file command on the file whos turn it is in the iteration. Something like this:

# loop thru control file
while true
do
read {1st file_name}
#process each line here with file command
#Perform string comparisons
test "string" = "string" #strings are equal
test "string" != "string" #strings are not equal
#Use case statement to determine how to unpack based on return of string comparison
done < $INPUT_CONTROL_FILE


When you call the file command will print out messages such as the following:

TAR FILE: tar file
COMPRESSED FILE: compressed data, block compressed, 16 bits
GZIP FILE: awk program text



Hope this helps.

Tony