| Michael Leone on 13 Mar 2012 08:26:56 -0700 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: [PLUG] Need some script advice |
On Tue, Mar 13, 2012 at 11:19 AM, Frank Szczerba <frank@szczerba.net> wrote:
> You could just wild card it like you do with the copy:
>
> if [ -f *.zip ]
> then
> echo 'Adding to archive'
> cp *.zip /Archive
> mailx -s "All good!" ...
> else
> echo 'File not found!'
> mailx -s "Problem making archive! Come look" .....
> fi
>
> will work just fine if there's never more than one zip file present. If there might be more than one, you can do:
>
> for zip in *.zip
> do
> if [ -f $zip ]
> then
> echo 'Adding to archive'
> cp $zip /Archive
> mailx -s "All good!" ...
> else
> echo 'File not found!'
> mailx -s "Problem making archive! Come look" .....
> fi
> done
No, there will only ever be 1 zip file present.
Here's what I have so far:
#!/bin/bash -
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#
# Go execute the Collector script, and rsync the output back here
#
/usr/bin/ssh user@IP '/Scripts/snag-files.sh' && /usr/bin/rsync -rvz
--timeout=90 --delete-excluded user@IP:/home/user/snagged-files/
/VendorInvoices/
echo -e Done remote execution "\n"
TREE='/VendorInvoices'
if [ "$(/bin/ls -A $TREE)" ]; then
#
# Copy the ZIP over to the archive, for safety's sake
#
/bin/cp /VendorInvoices/*.zip /VendorInvoicesArchive/
ZipFileName=$(/bin/ls -A /VendorInvoicesArchive/)"
#
# Check to make sure file exists in archive. If not, mail and exit
out. Else explode all files out individually
#
if [ -f $ZipFileName]
#
# Unzip anything collected
#
# -j = ignore paths
# -d = path to put all extracted files
#
/usr/bin/unzip -j /VendorInvoices/*.zip -d /VendorInvoices
#
# Kill the zip file (it's in the archive, anyway - see above)
#
/bin/rm /VendorInvoices/*.zip
#
# Mail the list 'o files
#
/bin/ls -l /VendorInvoices | /usr/bin/awk \!'/total/
{printf("%10s %2s %3s %20s \n", $6,$7,$8,$9)}' | mailx -s "List of
invoices for $(date '+%Y-%m-%d')" emailaddresses here
else
/bin/ls -s "ERROR copying invoice!! Come look"
emailaddresseshere
fi
else
mailx -s "No invoices received for $(date '+%Y-%m-%d')"
emailaddresseshere </Scripts/EmptyMailBody
fi
___________________________________________________________________________
Philadelphia Linux Users Group -- http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug