Expect script to run a Shell script on remote server

Hi All,

I am using a expect script to run a shell script on remote server, the code is as follows. But the problem is that it executes only first command, and hangs it doesn't run the next commands.

spawn ssh $uid@$host
expect "password:"
send "$password\r"
expect "*\r"
send "$HOME/arcsout.sh\r"
expect "*\r"
send "exit\r"
expect eof

The script is exiting after running first line from arcsout.sh, it is because of send "exit\r" command.

So instead i want to send ctrl -c to the remote server through "send"

How this can be achieved.

ssh, scp, sftp, sudo, su, and pretty much any sane login system are all specifically designed to prevent you from using stored, plaintext passwords. That you bludgeon it into working with a third-party hacking tool is a subtle hint, writ in mile-high flashing neon letters, that you're really not supposed to do this. Unfortunately this isn't just an aesthetic consideration -- they've got good reason to consider retrievably-stored passwords a security nightmare.

If you use ssh keys -- a secure and noninteractive authentication method -- ssh/scp/sftp won't fight you at all. They'll work as designed directly, with no coercion or third-party utilities necessary: Just the right files in the right places lets you type ssh hostname /bin/sh < /path/to/scriptfile.sh and watch it go. You'll find tutorials on creating ssh keys plastered all over the internet, and if they give you trouble, we can help. Here's one of them.

The problem is with the expect line after the send of the shell script. You need to change that to specifically look for the shell prompt before you send the exit command. Your expect script is taking any output sent by the shell script as a valid match so it sends the exit command.