Script check ftp

De DiouxX's Wiki
Aller à : navigation, rechercher
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

Konsole.png
[user@ordi ~]$ /home/diouxx/Scripts/check-ftp.sh >> /home/diouxx/Scripts/check-ftp.log 2>&1


#!/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"