ppovb5fc7/Flight_control_Comprehensive/emuStart_try_docker_kill.sh

94 lines
2.2 KiB
Bash

#!/bin/bash
launch_file=$1
docker_ssh=$2
GAZEBO_IP=`ifconfig $3 |grep "inet "| cut -f 2 -d ":"|cut -f 1 -d " "`
group_count=0
file=envfile
if [ -f $file ]
then
`rm -rf $file`
fi
`touch $file`
group="ns="
port="htonsnumber"
x="name=\"x\""
y="name=\"y\""
x_diff="name=\"X_DIFF\""
y_diff="name=\"Y_DIFF\""
while read line
do
if [[ $line =~ $group ]]
then
let group_count=$group_count+1
temp=${line#*\"}
echo "GAZEBO_IP:$GAZEBO_IP" >> $file
echo "NAMESPACE:${temp%\"*}" >> $file
fi
if [[ $line =~ $port ]]
then
temp=${line%\"*}
echo "SOCKET_PORT:${temp##*\"}" >> $file
fi
if [[ $line =~ $x ]]
then
temp=${line%\"*}
echo "START_X:${temp##*\"}" >> $file
fi
if [[ $line =~ $y ]]
then
temp=${line%\"*}
echo "START_Y:${temp##*\"}" >> $file
fi
if [[ $line =~ $x_diff ]]
then
temp=${line%\"*}
echo "X_DIFF:${temp##*\"}" >> $file
fi
if [[ $line =~ $y_diff ]]
then
temp=${line%\"*}
echo "Y_DIFF:${temp##*\"}" >> $file
fi
done < $launch_file
i=0
index=0
while read line
do
case $(($i%7)) in
0) gazebo_ip[$index]=$line;;
1) namespace[$index]=$line;;
2) socket_port[$index]=$line;;
3) x_diff[$index]=$line;;
4) y_diff[$index]=$line;;
5) start_x[$index]=$line;;
6) start_y[$index]=$line;let index++;;
esac
let i++
done < $file
#`rm $file`
for((i=0;i<index;i++))
do
`sshpass -p '123456' ssh $2 "sudo docker stop ${namespace[$i]#*:} >/dev/null 2>&1; sudo docker rm ${namespace[$i]#*:} >/dev/null 2>&1"`
# `sshpass -p '123123' ssh $2 "sudo docker rm ${namespace[$i]#*:} >/dev/null 2>&1"`
# `sshpass -p '123123' ssh $2 "sudo docker create --name ${namespace[$i]#*:} -e NAMESPACE=${namespace[$i]#*:} -e GAZEBO_IP=${gazebo_ip[$i]#*:} -e SOCKET_PORT=${socket_port[$i]#*:} -e START_X=${start_x[$i]#*:} -e START_Y=${start_y[$i]#*:} -e X_DIFF=${x_diff[$i]#*:} -e Y_DIFF=${y_diff[$i]#*:} $4 >/dev/null 2>&1"`
# `sshpass -p '123123' ssh $2 "sudo docker start ${namespace[$i]#*:} >/dev/null 2>&1"`
echo "${namespace[$i]#*:} Done!!"
done
echo "All Done!!"