Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have simple script:


while getopts ":u:" opt; do
  case $opt in
      echo "Unknown flag has been used: -$OPTARG" >&2
      exit 1
      echo "Option -$OPTARG requires an argument." >&2
      exit 1

stty -echo
read -p "New password for user ${USER}: " USER_PWD
stty echo


I would like to use it on another machine without copying it there. So I'm doing:

cat myscript.sh | ssh myserver bash -s - -u some_user

However it doesn't prompt me for passwords, instead it outputs me only an error:

stty: standard input: Invalid argument Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

What I'm doing wrong? Is it impossible to being prompted when redirecting script like that?

Added: I realized that my script have more problems (like using $USER variable, that is standard environmental variable), however my question really is about prompting. I reduced a problem to this simple script:


read -p "Please write something: " SOME_VARIABLE
echo "Done"

And when I'm doing this:

cat test.sh | ssh user@server bash -s

It just echoes "Done", and doesn't let me to input anything on "read". Is it normal and why is that?

share|improve this question
How about: cat myscript.sh | ssh some_user@myserver bash -s - – Ketan Feb 19 '14 at 17:08
@Ketan Same story. :/ – Łukasz Zaroda Feb 19 '14 at 17:10

you don't have any permission to run query from remote machine with root priviliage, your error said it.

share|improve this answer
But I can login to this machine and login to mysql as root without any problems. How is it different from above command? – Łukasz Zaroda Feb 19 '14 at 17:19
ERROR 1045 (28000) said it. – PersianGulf Feb 19 '14 at 17:20
how do you login? via mysql? – PersianGulf Feb 19 '14 at 17:21
Everything is visible in cited code. I'm logging through SSH and trying to run commands from redirected content of script. One of those commands queries mysql, however instead of asking me for password, it just fails. – Łukasz Zaroda Feb 19 '14 at 17:28
wow, be sure you have permission problem from mysql, your mysql configured for localhost. modify it. – PersianGulf Feb 19 '14 at 17:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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