I have a ssh calling a script in a server, named /opt/scripts/script1.sh.

sshpass -p 'password' ssh user@ip /opt/scripts/script1.sh

(I know sshpass is not secure but there's a reason for that in this context)

This script does a bunch of stuff then calls another script, doing bash /opt/scripts/script2.sh.

If I interactively ssh into this machine, and run /opt/scripts/script1.sh, /opt/scripts/script2.sh is called. But if I do

sshpass -p 'password' ssh user@ip /opt/scripts/script1.sh

/opt/scripts/script2.sh is not called. I don't have an error (even doing set -x), nothing. I don't know why it works in one way but not in another. Can someone explain why this happens?

closed as unclear what you're asking by Flup, msp9011, Jeff Schaller, schily, Romeo Ninov Aug 22 '18 at 13:30

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • You mention that script1.sh "does a bunch of stuff" before starting script2.sh; do you still see the problem if you remove all that, so that script1.sh only contains the line bash script2.sh? – JigglyNaga Aug 22 '18 at 9:44
  • 1
    Are you sure you're calling the same script? What does set -x say it's doing when it calls bash ...script2? – Jeff Schaller Aug 22 '18 at 10:39
  • 1
    Write a mcve. It helps you finding the problem. – ceving Aug 22 '18 at 11:04