#!/bin/bash current=0 LIST=$(seq 0 1 24) login="root" from="/opt/scripts/start_script.sh" to="/opt/" host_ip="" source ./node_list.sh # Function to resolve th ip of a given host function resolveip(){ local host="$1" if [ -z "$host" ];then host_ip="resolving failed" else local ip=$( getent hosts "$host" | awk '{print $1}' ) if [ -z "$ip" ];then ip=$( dig +short "$host" ) if [ -z "$ip" ];then # echo "unable to resolve '$host'" >&2 host_ip="resolving failed" else # echo "$ip" host_ip=$ip fi else # echo "$ip" host_ip=$ip fi fi } for i in $LIST ; do found=false # search for node in defined node list (array) for j in "${NODES[@]}"; do for k in $j; do #echo $j if [[ $i -eq $k ]]; then found=true fi done done if [[ $i -lt 10 ]];then current=0$i else current=$i fi if [ "$found" = true ]; then # delete node from known-host list to avoid problems when switching between deb and tc ssh-keygen -f "/home/apu/.ssh/known_hosts" -R "apu$current" > /dev/null 2>&1 # get node ip resolveip "apu$current" echo "Copying $path to apu$current with the IP $host_ip..." ssh -o StrictHostKeyChecking=no "$login"@"apu$current" "mv $from $to" & sudo rsync -ahx --stats --info=progress2 -e 'ssh -o StrictHostKeyChecking=no' /home/apu/testbed_files/apu-tb-systemd/apu_init.service root@"apu$current":/etc/systemd/system/ ssh -o StrictHostKeyChecking=no "$login"@"apu$current" "systemctl daemon-reload" & else # only inform the user about missing node defines when defining ranges by him-/herself if [ "$all" = false ]; then echo "Node apu$current not defined" fi fi done