expect command in ubuntu

6,584

You need to make your file executable:

chmod +x script.sh

and run it like:

./script.sh
Share:
6,584
CodZilla
Author by

CodZilla

Updated on September 18, 2022

Comments

  • CodZilla
    CodZilla over 1 year

    I've searched all over SuperUser, but couldn't get the solution. Here is a script that am using for ssh using expect. I'm using ubuntu and I've installed expect using aptitude install expect.

    #!/usr/bin/expect -f
    
    spawn ssh user@server
    expect "Password:"
    send "mypassword\r"
    interact
    

    When I run this script file, sh script.sh, I'm getting this error,

    test.sh: 3: spawn: not found
    couldn't read file "Password:": no such file or directory
    test.sh: 5: send: not found
    test.sh: 6: interact: not found
    

    I've tried with this posts, but not working, Ubuntu 10.04 using ssh without entering my password

    Thanks,

    • Mat
      Mat about 10 years
      How are you running the script exactly? (Exact thing you type on the command line.)
    • CodZilla
      CodZilla about 10 years
      I use user name, server name and password in the file itself. So no input parameters. Then i run the file 'script.sh' as sh script.sh
    • Mat
      Mat about 10 years
      You're specifically asking the shell to run your script. Make it executable (chmod +x ./script.sh) then run it (./script.sh). And don't call an expect script .sh, that's confusing - it's not a shell script.
    • CodZilla
      CodZilla about 10 years
      @Mat, thanks a lot. I've given execute permission and ran it as ./script.sh. And right, it's not a shell script. I was unaware of that.