1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2024-12-14 12:37:31 +00:00
ctrl/scripts/clisocket.sh

54 lines
1 KiB
Bash
Raw Normal View History

#!/bin/bash
if [ -z "$1" ]; then
echo "No toNode supplied"
exit 1
fi
if [ -z "$2" ]; then
echo "No shell path supplied"
exit 1
fi
if [ -z "$3" ]; then
echo "No cmd supplied"
exit 1
fi
nodes=$1
shell=$2
command=$3
IFS=',' read -r -a array <<<"$nodes"
function sendMessage() {
2023-01-10 05:56:01 +00:00
cat >msg-"$element".yaml <<EOF
[
{
"toNodes": ["${element}"],
"method": "cliCommand",
"methodArgs":
[
"${shell}",
"-c",
'echo "--------------------${element}----------------------" && ${command}',
],
"replyMethod": "fileAppend",
"retryWait": 5,
"ACKTimeout": 10,
"retries": 1,
"replyACKTimeout": 10,
"replyRetries": 1,
"methodTimeout": 10,
"replyMethodTimeout": 10,
"directory": "./data/",
"fileName": "debug.log",
},
]
EOF
}
for element in "${array[@]}"; do
2023-01-10 05:56:01 +00:00
sendMessage element "$command"
nc -U ./tmp/ctrl.sock <msg-"$element".yaml
done