Sunday, May 5, 2024
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 8414  / 1 Year ago, wed, january 25, 2023, 1:15:04

I am writing an script that needs to generate another script that will be used to shutdown an appserver...



This is how my code looks like:



echo "STEP 8: CREATE STOP SCRIPT"
stopScriptContent="echo "STOPING GLASSFISH PLEASE WAIT..."

cd glassfish4/bin

chmod +x asadmin

./asadmin stop-domain

#In order to work it is required that the original folder of glassfish don't contain already any #project, otherwise, there will be a conflict
"
${stopScriptContent} > stop.sh
chmod +x stop.sh


But it is not being created correctly, this is how the output stop.sh looks like:



"STOPING GLASSFISH PLEASE WAIT..."
cd glassfish4/bin
chmod +x asadmin
./asadmin stop-domain
#In order to work it is required that the original folder of glassfish don't contain already any #project, otherwise, there will be a conflict



As you see, lots of things are wrong:




  • there is no echo command

  • is taking the
    literaly so there is no new line



My doubts are:




  • What is the correct way of making an .sh script create another .sh script.

  • What do you thing I am doing wrong?


More From » command-line

 Answers
6

If you want to use echo with escaped characters like
you should add the -e switch echo -e " ... ". However it may be easier to use cat with a here document instead



cat > stop.sh <<EOF
echo "STOPING GLASSFISH PLEASE WAIT..."
cd glassfish4/bin
chmod +x asadmin
./asadmin stop-domain
#In order to work it is required that the original folder of glassfish don't contain already any #project, otherwise, there will be a conflict
EOF
chmod +x stop.sh

[#28967] Thursday, January 26, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raldership

Total Points: 222
Total Questions: 115
Total Answers: 124

Location: North Korea
Member since Fri, Nov 4, 2022
2 Years ago
;