#!/bin/bash usage() { echo "Usage: ${0} " exit 1 } get_user_hosts() { local User=${1} local Domain=${2} Cmd="curl -s http://cloud16.cvtt.vpn:6789/admin/cvtt_hosts" Cmd="${Cmd} | ${HOME}/bin/hjson -j" Cmd="${Cmd} | jq -r" Cmd="${Cmd} --arg domain \"${Domain}\"" Cmd="${Cmd} --arg usr \"${User}\"" Cmd="${Cmd} '.[\$domain] | to_entries[] | select(.value.users[] | contains(\$usr)) | .key'" # echo $Cmd ### - FOR DEBUG ONLY eval ${Cmd} } Domain=cvtt.vpn echo "Started ${0} ${*} ..." RootDir=${1} if [ ! -d "${RootDir}" ]; then usage fi cd ${RootDir} Cmd="git pull" echo ${Cmd} && eval ${Cmd} for User in cvtt oleg do echo "User=$User" Cmd="mkdir -p ${RootDir}/${User}" echo ${Cmd} && eval ${Cmd} hosts=$(get_user_hosts ${User} ${Domain}) echo ${hosts} for host in ${hosts} do echo "====================" echo "${host}:${User}" Cmd="ssh ${User}@${host}.${Domain} 'crontab -l' | tee ${RootDir}/${User}/${host}.cron" echo ${Cmd} && eval ${Cmd} done done cd ${RootDir} Cmd="find -type f -empty -delete -print" echo ${Cmd} && eval ${Cmd} Cmd="find -type d -empty -delete -print" echo ${Cmd} && eval ${Cmd} Cmd="git add ." echo ${Cmd} && eval ${Cmd} Cmd="git commit -a -m '$(date)'" echo ${Cmd} && eval ${Cmd} Cmd="git pushall" echo ${Cmd} && eval ${Cmd} echo "Done ${0} ${*}"