UsiScript
#!/bin/bash ## Original author = Sylvain HORRIERE #" modify on 15/11/2015 ## description = ## For each line in the file input, get the webserver and check the urls #Variables #LISTDATA="liste_urls.csv" RESULTFILE="liste_urls_verif.csv" SEPARE=";" OPENSSLPRG=/usr/bin/openssl DEFHTTPSPORT="443" DOMCDC="dede.fr" #usage function usage () { echo "Usage: $0 [-h] [-f
] -s
" echo " csv format = appliname;url" exit 1; } #Check the arguments given. while getopts "hf:" opt do case $opt in h) usage ;; # f argument is a file path; LISTDATA will contains this value f) LISTDATA="$OPTARG";; s) SEPARE="$OPTARG";; *);; esac done #If the file argument is empty if [ "$LISTDATA" = "" ]; then echo "Enter the filepath =" read LISTDATA fi # We check if the file $LISTDATA exist if [ ! -f $LISTDATA ]; then echo "! The file $LISTDATA doesn't exist." exit 1 else #put a line with columns titles echo "Appli;Servers" > $RESULTFILE fi # While the read line, we do the command while read line do APPLI="" HOST="" SEPOK=$(echo $line|grep $SEPARE|wc -l) if [ $SEPOK -gt 0 ];then echo " " echo "Line = $line" APPLI=$(echo $line|cut -d$SEPARE -f1) if [ "$APPLI" != "" ]; then HOST=$(host -t CNAME $APPLI|sed 's/has address/ (/g') if [ $? -gt 0 ]; then HOST="Error on host $APPLI" HOSTOK=0 echo "! Error when try to find the host for $APPLI" echo " " fi fi #On ecrit la premiere ligne est on creer la deuxieme FINALRESUTL=${APPLI}${SEPARE}${HOST} echo $FINALRESUTL >> $RESULTFILE else echo "No separator $SEPARE found" fi done < $LISTDATA