1

I made a bash script that contains the following:

#!/bin/bash
screen -dmS xccda "$(cd /root/constella && ./daemon.sh)"
screen -dmS xccwa "$(cd /root/constella && ./wallet.sh)"
screen -dmS xprda "$(cd /root/Prosus_Money && ./daemon.sh)"
screen -dmS xprwa "$(cd /root/Prosus_Money && ./wallet.sh)"
screen -dmS litda "$(cd /root/LithiumBit/build/release/src && ./daemon.sh)"
screen -dmS litwa "$(cd /root/LithiumBit/build/release/src && ./wallet.sh)"
screen -dmS lukada "$(cd /root/luka/cryptonote/build/release/src && ./daemon.sh)"
screen -dmS lukawa "$(cd /root/luka/cryptonote/build/release/src && ./wallet.sh)"
screen -dmS chaucha "$(cd /root/daemons/ && ./chauchad)"
screen -dmS litecoin "$(cd /root/daemons/litecoin-0.15.1/src && ./litecoind)"

What I want is this script to run those scripts in screen sessions but when I run my script with sh main.sh or ./main.sh it doesn't open screens sessions and this is what happens

i execute ./main sh and nothing shows and script never ends

When run individually each of those shell scripts runs like this

runs pretty well :c

2

Let's start with just the first couple of lines of your script. The issue affects all of them but it's easier to deal here with just one.

#!/bin/bash
screen -dmS xccda "$(cd /root/constella && ./daemon.sh)"

If you're declaring this as a bash script, don't use sh to run it. Either set the permissions and run it as ./main.sh or else use the right shell bash main.sh.

Now, why the script appears to hang. The screen session is passed a double-quoted string. Somewhat simplistically this means that the shell is allowed to evaluate expressions and variables beginning with $. You have included an $( ... ) instruction, which tells the shell to execute its contents and replace the entire string with the result of whatever it has written to stdout. Obviously for that replacement to occur the command has to complete. But yours doesn't. Furthermore, you didn't want the output anyway.

In summary,

  1. Use the correct shell interpreter
  2. Don't use double quotes here - use single quotes so that the shell won't parse the contents
  3. Don't try to evaluate the command and use its output. Just execute it.

Here is the revised start of your script; remember to apply similar changes throughout:

#!/bin/bash
screen -dmS xccda 'cd /root/constella && ./daemon.sh'
  • Thanks for your answer i replaced all commands in the file like this #!/bin/bash screen -dmS xccda 'cd /root/constella && ./daemon.sh' screen -dmS xccwa 'cd /root/constella && bash -c sh wallet.sh' screen -dmS xprda 'cd /root/Prosus_Money && ./daemon.sh' screen -dmS xprwa 'cd /root/Prosus_Money && ./wallet.sh' screen -dmS litda 'cd /root/LithiumBit/build/release/src && ./daemon.sh'.... but when executing screen -ls it says No Sockets found in /var/run/screen/S-root. – Rodrigo Oct 2 '18 at 21:50
  • That's almost entirely unreadable. I think you probably ran screen -ls as root, but you didn't run your script as root. Or else all the screen sessions exited immediately. – roaima Oct 2 '18 at 21:54
  • sorry about previous comment screen should not terminate inmediately since all script run a daemon in the foreground (it shows outputs) and not in the background it's weird – Rodrigo Oct 2 '18 at 21:58
  • @Rodrigo I appreciate that they shouldn't terminate immediately. I'm offering two possible reasons to explain what you saw. – roaima Oct 2 '18 at 22:00
  • ohh also i ran scripts as root user since i'm logged in as root this is so weird i'll keep searching thanks for your help – Rodrigo Oct 2 '18 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.