I'm writing a shell script that will respond to a prompt. For example, when I execute a file, the executed file will then prompt the user with this:

Please enter the password:

Then I want the script to automatically place something there for this prompt.

I understand "expect" is something I can use. However, I am using SSH and I do not have root on the server I am connected to and thus I cannot install "expect" there as I do not have permission.

I have two options: Either is there another way to respond to a prompt outside of expect? Or can I run a script on my local machine outside of the SSH connection and then run that script on this SSH machine?

I am trying to enter the numbers 000 to 999 (and all numbers in between) to try as the password. So I am building loops to do this( I know how to do this, I just DK how to make it respond to the prompt) , so I'm not sure if there is something outside of expect that I can do. I just want to know if there is some way to do this.

  • If I understand correctly you are trying to bruteforce a three-digit PIN code on a remote server. Are you sure you are allowed to do this? :-)
    – nwk
    Dec 16, 2014 at 20:23
  • yes it's a wargame server
    – king
    Dec 16, 2014 at 22:32

1 Answer 1


You don't need to install Expect on the server. Write an Expect script instead of running expect from a shell script. Have the Expect script itself spawn the SSH client, connect to the server and then loop through the numbers.

To save yourself some effort you can record a session where you log in to the server and try some number with autoexpect. Save the resulting script as, e.g., wargame.exp then add the loop to it. See https://www.tcl.tk/man/tcl8.5/tutorial/Tcl10.html (Expect scripts are Tcl code).

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.