Advertisement
Guest User

Untitled

a guest
Mar 13th, 2012
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.28 KB | None | 0 0
  1. #!/bin/bash -
  2.  
  3. #you don't need to specify paths for binaries since you include them in this $PATH variable.
  4. export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  5. #
  6. # Go execute the Collector script, and rsync the output back here
  7. #
  8. #specify user and remote site
  9. USER="someuser"
  10. REMOTE="192.168.1.100"
  11. ssh $USER@$REMOTE '/Scripts/snag-files.sh' && rsync -rvz --timeout=90 --delete-excluded $USER@$REMOTE:/home/user/snagged-files/ /VendorInvoices/
  12.  
  13. echo -e "Done remote execution\n"
  14.  
  15. TREE='/VendorInvoices'
  16. EMAILS="my@email.com another@email.com"
  17.  
  18. #change working directory
  19. cd $TREE
  20.  
  21. if [ ! -z "$(ls -A)" ]; then
  22.  
  23.     #loop will only run once if there's only one file.
  24.     for file in *.zip;do
  25.     #
  26.     # Unzip anything collected
  27.     #
  28.     # -j = ignore paths
  29.     # -d = path to put all extracted files
  30.     #
  31.     zipfile=$file
  32.     unzip -j "$zipfile"
  33.  
  34.     #
  35.     # Move zip file to archive and
  36.     # Mail the list 'o files
  37.     #
  38.     if mv $zipfile /VendorInvoicesArchive/; then
  39.         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
  40.     else
  41.         mailx -s "ERROR copying invoice!! Come look" $EMAILS
  42.     fi
  43.     done
  44. else
  45.     mailx -s "No invoices received for $(date '+%Y-%m-%d')" $EMAILS < /Scripts/EmptyMailBody
  46. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement