Advertisement
Guest User

Untitled

a guest
Mar 13th, 2012
73
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.  
  17. #change working directory
  18. cd $TREE
  19.  
  20. if [ ! -z "$(ls -A)" ]; then
  21.  
  22.     #loop will only run once if there's only one file.
  23.     for file in *.zip;do
  24.     #
  25.     # Unzip anything collected
  26.     #
  27.     # -j = ignore paths
  28.     # -d = path to put all extracted files
  29.     #
  30.     zipfile=$file
  31.     unzip -j "$zipfile"
  32.  
  33.     #
  34.     # Move zip file to archive and
  35.     # Mail the list 'o files
  36.     #
  37.     if mv $zipfile /VendorInvoicesArchive/; then
  38.         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
  39.     else
  40.         mailx -s "ERROR copying invoice!! Come look" $EMAILS
  41.     fi
  42.     done
  43. else
  44.     mailx -s "No invoices received for $(date '+%Y-%m-%d')" $EMAILS < /Scripts/EmptyMailBody
  45. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement