Hi everyone,
I would need someone to enlighten me and support me for the creation of a script in bash that allows me from the first server on which it will be launched to manage an application in jar (start, stop, deploy) on all the other machines (in total 32) .
I thought of something like this as a script that provides the option to choose a menu option:
#!/bin/bash
## ----------------------------------
# Step #1: Define variables
# ----------------------------------
SERVER=/data/SpringBoot/Shaw/scripts/server_list/list.txt
# ----------------------------------
# Step #2: User defined function
# ----------------------------------
pause(){
read -p "Press [Enter] key to continue..." fackEnterKey
}
start_shaw ()
{
for serv_name in $(cat $SERVER)
do
ssh $serv_name 'bash -s' < /data/SpringBoot/Shaw/app/Shaw_start.sh
echo "Starting Shaw on $serv_name"
sleep 5
done
echo
wait
exit 0
}
# do something in two()
two(){
echo "two() called"
pause
}
# function to display menus
show_menus() {
clear
echo "~~~~~~~~~~~~~~~~~~~~~"
echo "SEBASTIAN SHAW MANAGEMENT"
echo "~~~~~~~~~~~~~~~~~~~~~"
echo "1. Start Service"
echo "2. Stop Service"
echo "3. Exit"
}
# read input from the keyboard and take a action
# invoke the one() when the user select 1 from the menu option.
# invoke the two() when the user select 2 from the menu option.
# Exit when user the user select 3 form the menu option.
read_options(){
local choice
read -p "Enter choice [ 1 - 3] " choice
case $choice in
1) start_shaw ;;
2) two ;;
3) exit 0;;
*) echo -e "${RED}Error...${STD}" && sleep 2
esac
}
# ----------------------------------------------
# Step #3: Trap CTRL+C, CTRL+Z and quit singles
# ----------------------------------------------
trap '' SIGINT SIGQUIT SIGTSTP
# -----------------------------------
# Step #4: Main logic - infinite loop
# ------------------------------------
while true
do
show_menus
read_options
done
where the script Shaw_start.sh that is stored on each server is:
#!/bin/bash
nohup /data/jdk1.8.0_151/bin/java -jar -Xmx1024M Shaw.jar &
echo $! > pid.file &
exit 0
The problem is that although I get out that he is performing the starting then in the end he did nothing.
No service is started and its file is created.
Can someone please help me?