need help scripting tar over ssh

Hello - I've used 'expect' in FTP scripts before without any problems, but am unsure as to how I would script a tar over ssh session?

I need to send password for authentication to the remote Suse machine.

:confused:

Any assistance provided would be GREATLY appreciated.

I've used the following post as reference before:

http://www.unix.com/unix-advanced-expert-users/14417-loops-within-ftp-comands.html

Hope it helps.

Thanks. That is good to know, but unfortunately it's not what I need. I have a lot of data (every directory off of root filesystem) to transfer to a remote server nightly.

I would like to use a command similar to this:

# tar cvf - /var | ssh user@remoteserver 'tar xvf -'

...the problem is I have not been able to get this to work within an 'expect' script.

Is it possible to do so? Due to security restrictions, all accounts on the remote server must have passwords, so I must send the password in the script.

If you use ssh, why don't you exchange ssh-keys to circumvent the need for a password? Just create the key (see: ssh-keygen) without a password and put it into the file authorized_keys.

bakunin

Thx bakunin -

I had just discussed this with a co-worker here and it may be an option although we currently don't have sshd running on the local UnixWare servers. It is installed and running on the remote Suse Linux server that we are transferring the files too, though.

I assume sshd must be installed and running on both machines, but it shouldn't be a problem.

I was a bit short on my answer, so here is the long version:

You can't do, what you (originally) wanted to do, because

  1. using the <stdin> of ssh to transport some file like in "proc | ssh ..." make this <stdin> unusable for any other purposes, namely input of passwords. This is a general problem, which is: "proc1 | proc2 < file3" is not possible because <stdin> of proc2 can either accept input from proc1 OR from file3 but not both.

  2. to be reasonably eligible to do input processing as a means of file transfer (the "proc | ssh ...") ssh must make sure its <stdin> is not used elsewhere, especially not input. This (and because of some security reasons like reading the terminal session at the terminals device file) is why ssh doesn't use <stdin> to get the password but reads directly from the keyboard. I'd be very much surprised if expect is able to emulate this.

So, the bottom line is: i haven't ever needed to work with expect, so my experience is limited, but probably passing passwords to ssh is impossible.

bakunin

Thanks for your input. I was able to run ssh-keygen and get the trusted relationship set up. It works perfectly.

Thanks again.