Advertisement
Guest User

ftpnotify

a guest
Oct 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.16 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Copyright to D.Wanin and J.Stordeur
  4. # Script to track one single file in FTP then send MAIL
  5. # require SMTP service to be fully configured and running
  6.  
  7. #tracker pour un seul fichier. A adapter pour un tracker de dossier (diff -r -C 0 avec un mount du dossier FTP
  8. #pour ne pas s'amuser à télécharger chaque fichier pour la comparaison !)
  9.  
  10. curl --ftp-method nocwd -G -u <user>:<password> --url '<urlToFile>' -o <output>
  11.  
  12. # Débugger curl en ajoutant --verbose
  13. # <output>.old est le backup de <output> (ex : /tmp/geez.morty)pour la comparaison
  14. #ajouter les TAG nécéssaire si tu passes par SFTP ou FTPS
  15.  
  16. DIFFERENCE=`diff --text -C 0 <output>.old <output>
  17. RETOUR=$?
  18. mv <output> <output>.old
  19. if test $RETOUR -eq 0 ;then     # Fichiers identiques
  20.         # was for debug echo "same"
  21.         exit 0
  22. fi
  23.  
  24. if test $RETOUR -eq 2 ;then # Nouveau fichier
  25.         # was for debug echo "new"
  26.         # do something
  27. fi
  28.  
  29. if test $RETOUR -eq 1 ;then     # Fichier modifié
  30.         cat <content of mail> > email
  31.         /usr/sbin/sendmail <email@hostname> < email # lis le man pour la structure du fichier "email"
  32.         # was for debug echo "mod" >> stdout
  33. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement