Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash -
- #you don't need to specify paths for binaries since you include them in this $PATH variable.
- 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
- #
- #specify user and remote site
- USER="someuser"
- REMOTE="192.168.1.100"
- ssh $USER@$REMOTE '/Scripts/snag-files.sh' && rsync -rvz --timeout=90 --delete-excluded $USER@$REMOTE:/home/user/snagged-files/ /VendorInvoices/
- echo -e "Done remote execution\n"
- TREE='/VendorInvoices'
- EMAILS="my@email.com another@email.com"
- #change working directory
- cd $TREE
- if [ ! -z "$(ls -A)" ]; then
- #loop will only run once if there's only one file.
- for file in *.zip;do
- #
- # Unzip anything collected
- #
- # -j = ignore paths
- # -d = path to put all extracted files
- #
- zipfile=$file
- unzip -j "$zipfile"
- #
- # Move zip file to archive and
- # Mail the list 'o files
- #
- if mv $zipfile /VendorInvoicesArchive/; then
- ls -l $TREE | awk '{printf("%10s %2s %3s %20s \n", $6,$7,$8,$9)}' | mailx -s "List of invoices for $(date '+%Y-%m-%d')" $EMAILS
- else
- mailx -s "ERROR copying invoice!! Come look" $EMAILS
- fi
- done
- else
- mailx -s "No invoices received for $(date '+%Y-%m-%d')" $EMAILS < /Scripts/EmptyMailBody
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement