-
Notifications
You must be signed in to change notification settings - Fork 0
/
rename_var.sh
48 lines (38 loc) · 1.17 KB
/
rename_var.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
# Expand the SSH key path
# Set default SSH key location
DEFAULT_SSH_KEY="~/.ssh/id_rsa"
# Allow user to override the SSH key location
SSH_KEY=${SSH_KEY:-$DEFAULT_SSH_KEY}
TIMEOUT=60
# Fetch the IP addresses from Pulumi stack outputs
STACK_OUTPUT=$(pulumi stack output -j)
DROPLET_IPS=$(echo "$STACK_OUTPUT" | jq -r '.[]')
# Variables
USER="root"
TMUX_SESSION_NAME="app"
COMMAND="export SEEN_LIMI=\"84\""
# Function to start tmux session on a remote server
change_var() {
local IP=$1
{
echo "Starting tmux session on $IP -----------------------------------------------------"
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ${SSH_KEY} ${USER}@${IP} << EOF
tmux send-keys -t ${TMUX_SESSION_NAME} "${COMMAND}" C-m
EOF
echo "Tmux session started on $IP"
} &
PID=$!
(sleep $TIMEOUT && kill -HUP $PID) 2>/dev/null &
if wait $PID 2>/dev/null; then
echo "$IP: Tmux session started within timeout"
else
echo "$IP: Operation timed out"
fi
}
# Loop through the IPs and run the start_tmux_session function in parallel
for IP in $DROPLET_IPS; do
start_tmux_session "$IP" &
done
# Wait for all background processes to finish
wait