sporo zmian, nie pamiętam czego :)

This commit is contained in:
2023-07-08 13:12:31 +02:00
parent 060b2022d2
commit 192276ff80
38 changed files with 1260 additions and 51 deletions

51
bin/ec2-tmux Executable file
View File

@ -0,0 +1,51 @@
#!/bin/bash -x
#set -o errexit
set -o nounset
set -o pipefail
SESSION=$AWS_PROFILE
EC2_INSTANCES=$(aws ec2 describe-instances --filter "Name=instance-state-name,Values=running" --query "Reservations[*].Instances[*].[PublicIpAddress, Tags[?Key=='Name'].Value|[0]]" --output text|sed -E 's/\s+/,/g')
get_window() {
NAME=$1
window_id=$(tmux list-windows -t $SESSION -F "#W:#I" |grep $NAME|cut -d':' -f2)
echo "$window_id"
}
create_window() {
NAME=$1
COUNT=$(tmux list-windows -t $SESSION|wc -l)
WINDOW_ID=$(($COUNT))
tmux new-window -t $SESSION:$WINDOW_ID -n $NAME
}
attach_to_window() {
NAME=$1
HOST=$2
WINDOW=$(get_window $NAME)
if [ "$WINDOW" = "" ]
then
create_window $NAME
tmux send-keys -t $NAME "jssh $HOST" C-m
else
tmux split-window -t $NAME
tmux send-keys -t $NAME "jssh $HOST" C-m
fi
}
tmux has-session -t $SESSION 2>/dev/null
if [ $? != 0 ]; then
tmux new-session -d -s $SESSION
for INSTANCE in $EC2_INSTANCES
do
HOST=$(echo $INSTANCE|cut -d',' -f1)
NAME=$(echo $INSTANCE|cut -d',' -f2)
attach_to_window $NAME $HOST
done
fi
tmux attach-session -t $SESSION