55 lines
1.3 KiB
Plaintext
55 lines
1.3 KiB
Plaintext
|
#!/bin/bash
|
||
|
|
||
|
# exécute une commande dans un conteneur
|
||
|
|
||
|
SSHCMD="ssh -q -o LogLevel=ERROR -o StrictHostKeyChecking=no"
|
||
|
|
||
|
commande=$1
|
||
|
container=$2
|
||
|
# ne lancer la commande que si dans un conteneur (ssh)
|
||
|
onlyifcontainer=$3
|
||
|
silent=$4
|
||
|
CMD='eval'
|
||
|
|
||
|
ExecContainer()
|
||
|
{
|
||
|
ip="$1"
|
||
|
cmd="$2"
|
||
|
tcpcheck 2 $ip:22 &>/dev/null || return 1
|
||
|
$SSHCMD root@$ip "$cmd"
|
||
|
}
|
||
|
|
||
|
if [[ ${container} == "all" ]]
|
||
|
then
|
||
|
if [[ $(CreoleGet mode_conteneur_actif) == "oui" ]]
|
||
|
then
|
||
|
for grp in $(CreoleGet --groups)
|
||
|
do
|
||
|
if [[ ${grp} != 'root' ]] && [[ ${grp} != 'all' ]]
|
||
|
then
|
||
|
container_ip=$(CreoleGet "container_ip_${grp}")
|
||
|
if [ ! "$silent" = "yes" ]; then
|
||
|
echo "Exécution de la commande [${commande}] dans le conteneur ${grp}"
|
||
|
echo
|
||
|
fi
|
||
|
ExecContainer "$container_ip" "$commande"
|
||
|
if [ ! "$silent" = "yes" ]; then
|
||
|
echo
|
||
|
fi
|
||
|
fi
|
||
|
done
|
||
|
fi
|
||
|
else
|
||
|
if [ -n "$container" ]
|
||
|
then
|
||
|
container_ip=$(CreoleGet "container_ip_$container")
|
||
|
fi
|
||
|
if [ -n "$container_ip" ] && [ ! "$container_ip" = "127.0.0.1" ]
|
||
|
then
|
||
|
ExecContainer "$container_ip" "$commande"
|
||
|
elif [ "$onlyifcontainer" != "yes" ]
|
||
|
then
|
||
|
eval "$commande"
|
||
|
fi
|
||
|
fi
|