.scriptComm.sh: Difference between revisions
Jump to navigation
Jump to search
(Created page with "<syntaxhighlight lang="bash"> #!/bin/sh # comm entre serveurs # ["srv1 srv2 ... srvn"] "codeFile" # APA 20180108 # APA 20180325 server list # APA 20180406 cache added [ $# -e...") |
No edit summary |
||
Line 16: | Line 16: | ||
cat "${@: -1}" >"${cacheFile}" | cat "${@: -1}" >"${cacheFile}" | ||
chmod 500 "${cacheFile}" | chmod 500 "${cacheFile}" | ||
chown | chown infocepo: "${cacheFile}" | ||
hostList=$(hostList.sh "${@:1:$(($# -1))}") | hostList=$(hostList.sh "${@:1:$(($# -1))}") |
Latest revision as of 00:26, 9 March 2022
#!/bin/sh
# comm entre serveurs
# ["srv1 srv2 ... srvn"] "codeFile"
# APA 20180108
# APA 20180325 server list
# APA 20180406 cache added
[ $# -eq 0 ] &&exit
# initialisation des variables
baseDir="$(realpath "$(dirname $0)"/..)"
cacheFile=/tmp/"$(basename $0)"$$
# stock code en cache avec des accès limités
cat "${@: -1}" >"${cacheFile}"
chmod 500 "${cacheFile}"
chown infocepo: "${cacheFile}"
hostList=$(hostList.sh "${@:1:$(($# -1))}")
# signature du code
nameBase="$(cat ${cacheFile} |tr -c '[:alnum:]' '_' |cut -c 1-68 |tr -s '_' |sed -r 's#_$##' )"-$(md5sum ${cacheFile} |cut -c 1-2 )
resultName="${baseDir}"/log/comm.$(echo "${hostList}" |sha512sum | cut -c 1-16)."${nameBase}".gz
# si resultat non en cache, lancer le traitement
if [ -z "$(find "${resultName}" -mmin -6 2>/dev/null )" ] ;then
# lancement du code
## Enleve les lignes en doublons par serveur. Puis ne garde que les lignes superieur aux nombre de serveurs/2.
script.sh "${hostList}" "${cacheFile}" 2>/dev/null >/dev/null
countNumber=0
for hostName in $hostList ;do
cachePath="${baseDir}"/log/old/${hostName}-"${nameBase}"-$(date '+%Y%m%d')
zcat "${cachePath}".gz 2>/dev/null \
|awk '!seen[$0]++' \
|grep . |tee "${cacheFile}".result
[ "$(head -1 "${cacheFile}".result |wc -l)" -ge 1 ] &&((countNumber++))
done \
>"${cacheFile}".result2
triggerValue=$((countNumber / 2))
awk 'NR == FNR {count[$0]++; next}; count[$0] > '"${triggerValue}" "${cacheFile}".result2 "${cacheFile}".result2 \
| awk '!seen[$0]++' \
| gzip >"${cacheFile}".result
# mise en cache
mv "${cacheFile}".result "${resultName}"
fi
# affiche le resultat
zcat "${resultName}"
# clean cache
rm -f /tmp/"$(basename $0)"$$* 2>/dev/null