3

I have created a shell script as given below.But it is not reading username and password.What Iam expecting form this script is to login as a normal user to a remote machine and login to root user to run some commands there.

ssh -t [email protected] '
  echo "user logined !";
  su root -c "
    echo Give username :;
    read username;
    echo Give password :;
    read password;
    echo $username;
    echo $password;
  ";
'
1
  • Why do you not log in to 10.3.2.0 as root to start? Commented Mar 5, 2013 at 16:18

1 Answer 1

3

You need to escape the $'s for the variables inside the quotes:

ssh -t [email protected] '
  echo "user logined !";
  su root -c "
    echo Give username :;
    read username;
    echo Give password :;
    read password;
    echo \$username;
    echo \$password;
  ";
'

Otherwise, the shell created by the ssh command as the qbadmin user is going to perform string interpolation on $username and $password before executing the su command.

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

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.