Changeset 412 for trunk/push-web


Ignore:
Timestamp:
Jan 28, 2020, 4:56:40 PM (5 years ago)
Author:
g7moreau
Message:
  • rename TMP to CACHE_FOLDER. User can change it inside the configuration file (update sample)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/push-web

    r411 r412  
    2020GRAPH_SHIFT=1
    2121
     22CACHE_TIMEOUT=50
     23CACHE_FOLDER='/tmp/klask-push-web'
     24
    2225if [ -f /etc/klask/push-web.conf ]
    2326then
     
    2528fi
    2629
    27 TMP='/tmp/klask-push-web'
    28 
    2930
    3031# remote command
    3132DOT=/usr/bin/dot
    3233
    33 
    34 mkdir -p ${TMP}
    35 if [ ! -d ${TMP} ]
     34mkdir -p ${CACHE_FOLDER}
     35if [ ! -d ${CACHE_FOLDER} ]
    3636then
    37    echo "Error: Folder ${TMP} do not exist !"
     37   echo "Error: Folder ${CACHE_FOLDER} do not exist !"
    3838   exit 1
    3939fi
    40 cd ${TMP}
    41 
     40cd ${CACHE_FOLDER}
    4241
    4342LOCALTIME=$(date "+%Y-%m-%d %H:%M")
    4443TIMEFILE=$(date "+%Y-%m-%d.%H-%M")
    4544
    46 CACHE_TIMEOUT=50
    47 find ${TMP}/ -type f -a -mtime +${CACHE_TIMEOUT} -delete
    48 
    49 klask exportsw --format dot --modulo ${GRAPH_MODULO} --shift ${GRAPH_SHIFT} > ${TMP}/switch-map.txt.new
    50 klask exportsw                                                              > ${TMP}/switch-db.txt.new
    51 
    52 klask exportdb    > ${TMP}/hostname-db.txt
    53 klask ip-free     > ${TMP}/ipfree-db.txt
    54 klask bad-vlan-id > ${TMP}/badvlan-db.txt
    55 
    56 cmp --silent ${TMP}/switch-db.txt.new ${TMP}/switch-db.txt || {
    57    mv -f ${TMP}/switch-db.txt.new ${TMP}/switch-db.${TIMEFILE}.txt;
    58    ln -sf ${TMP}/switch-db.${TIMEFILE}.txt ${TMP}/switch-db.txt
    59    }
    60 
    61 cmp --silent ${TMP}/switch-map.txt.new ${TMP}/switch-map.txt || {
    62    mv -f ${TMP}/switch-map.txt.new ${TMP}/switch-map.${TIMEFILE}.txt;
    63    ln -sf ${TMP}/switch-map.${TIMEFILE}.txt ${TMP}/switch-map.txt
    64    }
    65 
     45find ${CACHE_FOLDER}/ -type f -a -mtime +${CACHE_TIMEOUT} -delete
     46
     47klask exportsw --format dot --modulo ${GRAPH_MODULO} --shift ${GRAPH_SHIFT} > ${CACHE_FOLDER}/switch-map.txt.new
     48klask exportsw                                                              > ${CACHE_FOLDER}/switch-db.txt.new
     49
     50klask exportdb    > ${CACHE_FOLDER}/hostname-db.txt
     51klask ip-free     > ${CACHE_FOLDER}/ipfree-db.txt
     52klask bad-vlan-id > ${CACHE_FOLDER}/badvlan-db.txt
     53
     54cmp --silent ${CACHE_FOLDER}/switch-db.txt.new ${CACHE_FOLDER}/switch-db.txt || {
     55   mv -f ${CACHE_FOLDER}/switch-db.txt.new ${CACHE_FOLDER}/switch-db.${TIMEFILE}.txt;
     56   ln -sf ${CACHE_FOLDER}/switch-db.${TIMEFILE}.txt ${CACHE_FOLDER}/switch-db.txt
     57   }
     58
     59cmp --silent ${CACHE_FOLDER}/switch-map.txt.new ${CACHE_FOLDER}/switch-map.txt || {
     60   mv -f ${CACHE_FOLDER}/switch-map.txt.new ${CACHE_FOLDER}/switch-map.${TIMEFILE}.txt;
     61   ln -sf ${CACHE_FOLDER}/switch-map.${TIMEFILE}.txt ${CACHE_FOLDER}/switch-map.txt
     62   }
     63
     64# keep trace of old switch map
    6665old_switch_db=$((echo 'command <tt>klask exportsw --format txt</tt>';
    67       (cd ${TMP}/; ls -1 switch-db.20[0-9][0-9]-[0-9][0-9]-[0-9][0-9].[0-9][0-9]-[0-9][0-9].txt;) \
     66      (cd ${CACHE_FOLDER}/; ls -1 switch-db.20[0-9][0-9]-[0-9][0-9]-[0-9][0-9].[0-9][0-9]-[0-9][0-9].txt;) \
    6867      | sed -e 's/^switch-db\.//; s/\.txt$//;' \
    69       | xargs -r -I {} printf "<a href=\"switch-db.%s.txt\">%s</a>\n" '{}' '{}' \
     68      | xargs -r -I {} printf " <a href=\"switch-db.%s.txt\">%s</a>\n" '{}' '{}' \
    7069      ) \
    7170   | paste -sd ',' -)
    7271
    7372old_switch_map=$((echo 'graphviz';\
    74       (cd ${TMP}/; ls -1 switch-map.20[0-9][0-9]-[0-9][0-9]-[0-9][0-9].[0-9][0-9]-[0-9][0-9].txt;) \
     73      (cd ${CACHE_FOLDER}/; ls -1 switch-map.20[0-9][0-9]-[0-9][0-9]-[0-9][0-9].[0-9][0-9]-[0-9][0-9].txt;) \
    7574      | sed -e 's/^switch-map\.//; s/\.txt$//;' \
    76       | xargs -r -I {} printf "<a href=\"switch-map.%s.txt\">%s</a>\n" '{}' '{}' \
     75      | xargs -r -I {} printf " <a href=\"switch-map.%s.txt\">%s</a>\n" '{}' '{}' \
    7776      )\
    7877   | paste -sd ',' -)
    7978
    80 cat <<END > ${TMP}/index.html
     79
     80cat <<END > ${CACHE_FOLDER}/index.html
    8181<!DOCTYPE html>
    8282<html lang="en">
     
    205205END
    206206
    207 klask exportdb --format html >> ${TMP}/index.html
    208 
    209 cat <<END >> ${TMP}/index.html
     207klask exportdb --format html >> ${CACHE_FOLDER}/index.html
     208
     209cat <<END >> ${CACHE_FOLDER}/index.html
    210210 </div>
    211211
     
    217217END
    218218
    219 klask ip-free --format html >> ${TMP}/index.html
    220 
    221 cat <<END >> ${TMP}/index.html
     219klask ip-free --format html >> ${CACHE_FOLDER}/index.html
     220
     221cat <<END >> ${CACHE_FOLDER}/index.html
    222222 </div>
    223223
     
    229229END
    230230
    231 klask bad-vlan-id --format html >> ${TMP}/index.html
    232 
    233 cat <<END >> ${TMP}/index.html
     231klask bad-vlan-id --format html >> ${CACHE_FOLDER}/index.html
     232
     233cat <<END >> ${CACHE_FOLDER}/index.html
    234234 </div>
    235235
     
    283283      /usr/share/klask/svg-pan-zoom-klask.js \
    284284      /usr/share/klask/style-klask.css \
    285       ${TMP}/index.html \
    286       ${TMP}/*-db.txt \
    287       ${TMP}/switch-map.txt \
    288       ${TMP}/*.20[0-9][0-9]-[0-9][0-9]-[0-9][0-9].[0-9][0-9]-[0-9][0-9].txt \
     285      ${CACHE_FOLDER}/index.html \
     286      ${CACHE_FOLDER}/*-db.txt \
     287      ${CACHE_FOLDER}/switch-map.txt \
     288      ${CACHE_FOLDER}/*.20[0-9][0-9]-[0-9][0-9]-[0-9][0-9].[0-9][0-9]-[0-9][0-9].txt \
    289289      ${REMOTE_FOLDER}/
    290290
     
    298298      /usr/share/klask/svg-pan-zoom-klask.js \
    299299      /usr/share/klask/style-klask.css \
    300       ${TMP}/index.html \
    301       ${TMP}/*-db.txt \
    302       ${TMP}/switch-map.txt \
    303       ${TMP}/*.20[0-9][0-9]-[0-9][0-9]-[0-9][0-9].[0-9][0-9]-[0-9][0-9].txt \
     300      ${CACHE_FOLDER}/index.html \
     301      ${CACHE_FOLDER}/*-db.txt \
     302      ${CACHE_FOLDER}/switch-map.txt \
     303      ${CACHE_FOLDER}/*.20[0-9][0-9]-[0-9][0-9]-[0-9][0-9].[0-9][0-9]-[0-9][0-9].txt \
    304304      ${REMOTE_USER}@${REMOTE_SERVER}:${REMOTE_FOLDER}/
    305305
Note: See TracChangeset for help on using the changeset viewer.