2

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,

CodZilla
  • 23
  • 1
  • 3
  • How are you running the script exactly? (Exact thing you type on the command line.) – Mat Mar 03 '14 at 11:07
  • 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` – CodZilla Mar 03 '14 at 11:20
  • 1
    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. – Mat Mar 03 '14 at 11:38
  • @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. – CodZilla Mar 03 '14 at 11:56

1 Answers1

1

You need to make your file executable:

chmod +x script.sh

and run it like:

./script.sh
maganap
  • 126
  • 2