Script check ftp : Différence entre versions
(Page créée avec « {{ Introduction | Ce script permet de vérifier si une connexion vers un serveur FTP est fonctionnel }} On peut l'insérer dans une tâche cron ou l'éxécuter de la mani... ») |
|||
| Ligne 6 : | Ligne 6 : | ||
<br> | <br> | ||
| − | <syntaxhighlight | + | <syntaxhighlight lang=bash> |
#!/bin/bash | #!/bin/bash | ||
Version actuelle datée du 3 mai 2019 à 12:34
Ce script permet de vérifier si une connexion vers un serveur FTP est fonctionnel
On peut l'insérer dans une tâche cron ou l'éxécuter de la manière suivante
#!/bin/bash
#Couleur affichage
VERT="\\033[1;32m"
NORMAL="\\033[0;39m"
ROUGE="\\033[1;31m"
ROSE="\\033[1;35m"
BLEU="\\033[1;34m"
BLANC="\\033[0;02m"
BLANCLAIR="\\033[1;08m"
JAUNE="\\033[1;33m"
CYAN="\\033[1;36m"
HOST=ftp.domain.com
LOGIN=USER
PASSWORD=PASSWORD
PORT=21
LOG_FILE=/home/diouxx/Scripts/check-ftp.log
#Fonction d'horodatage pour les log
#$1 = Texte a afficher apres l'horodatage
function horodate(){
horodate=`date +"\n%d"/"%m"/"%Y"-"%H":"%M":"%S -- "`
echo -e "$horodate$1"
}
exec 1>&2 >> $LOG_FILE
horodate "START FTP CONNEXION"
ftp -i -n $HOST $PORT << END_SCRIPT
quote USER $LOGIN
quote PASS $PASSWORD
ls
quit
END_SCRIPT
if [ $? != 0 ]
then
horodate "Connexion FTP \t\t\t$ROUGE[KO]$NORMAL"
else
horodate "Connexion FTP \t\t\t$VERT[OK]$NORMAL"
fi
horodate "END FTP CONNEXION"