-1

How does user input work for running local scripts remotely?

My script uses $1 for user input.

The remote machine names vary, so I wrote a script(main_script.sh), which also uses $1 to read the name of the remote machine.

Ex:

./main_script.sh remote3 lcl_script.sh <user_in>

But user input is not recognized. remote3 is the name of the remote machine

Main script:

ssh root@$1 'bash -s' < $2

where, $1 is for machine name. $2 is for the local script.

Local script:

printf "new setting:"
echo $1

where $1 is the user_in

1
  • Please post your scripts. Commented Mar 30, 2021 at 6:18

2 Answers 2

0

wrap the script name and user_in in quotes

./main_script.sh remote3 "~/lcl_script.sh <user_in>"

This question is source of answer

Passing variables in remote ssh command

Sign up to request clarification or add additional context in comments.

6 Comments

I tried putting in quote, but still didn't work.
Qualify the full path of the remote script? - eg. : ./main_script.sh remote3 "~/lcl_script.sh <user_in>"
Presumably the ssh keys and known_hosts are configured and logging into remote server occurs successfully without needing to enter the password?
Correct, no need to enter password.
Are you able to elaborate on what you define as "But user input is not recognized" - what does stdout display (and maybe stderr)?
|
0

I figured it out.
To make sure the user input is read, I had to add $3 (for user input) in the main script,
Main script is:

ssh root@$1 'bash -s' < $2 $3

I didn't have to change anything in the local script.
@irnerd, thanks for helping out.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.