Need help in automation

Hi, I wanted to automate the scp command where i do not want to enter the password each time. So thought of using expect command. Script is executing without any issues but files are not copied to remote server. Can any one help me?

Below is my shell script..

#!/bin/ksh

TMP_FILE="/tmp/testestest"
/usr/bin/expect -d <<EOD
spawn /usr/bin/scp $TMP_FILE user2@123.123.123.123:/tmp/backup/logs/
expect "password:"  { send "user1234\r" }
EOD

Output:

expect version 5.42.1
argv[0] = /usr/bin/expect  argv[1] = -d
set argc 0
set argv0 "/usr/bin/expect"
set argv ""
executing commands from command file
spawn /usr/bin/scp /tmp/testestest user2@123.123.123.123:/tmp/backup/logs/
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {31719550}

expect: does "" (spawn_id exp4) match glob pattern "password:"? no
********************************************************************************
* This system was LDAP clientized on Wed Aug  3 14:49:58 CUT 2011              *
********************************************************************************

expect: does "********************************************************************************\r\n* This system was LDAP clientized on Wed Aug  3 14:49:58 CUT 2011              *\r\n********************************************************************************\r\n" (spawn_id exp4) match glob pattern "password:"? no
user2@123.123.123.123's password:
expect: does "********************************************************************************\r\n* This system was LDAP clientized on Wed Aug  3 14:49:58 CUT 2011              *\r\n********************************************************************************\r\nwsadmin@159.202.157.176's password: " (spawn_id exp4) match glob pattern "password:"? yes
expect: set expect_out(0,string) "password:"
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "********************************************************************************\r\n* This system was LDAP clientized on Wed Aug  3 14:49:58 CUT 2011              *\r\n********************************************************************************\r\nwsadmin@159.202.157.176's password:"
send: sending "user1234\r" to { exp4 }

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

The proper way to automate SFTP is using keys. There are tutorials for 'passwordless ssh' all over the internet, which apply equally well to sftp, because they are in fact the same protocol.

It's very simple. Generating the right files and putting them in the right places will allow you to connect without a password without kludging it with a third-party brute-forcing utility.

This is also the preferred way to do it because it does not require you to store passwords. It is nearly impossible to keep reversibly-stored passwords safe.

I have tried to steps mentioned in Password less SSH. But for me still asking for password..

Steps Performed

1. ssh-keygen -t rsa
given empty passpharse
2. created dir in remote server
3. appended the public key into authorized_keys
4. tried to ssh but it is asking for password:mad:

Can anyone help me

Have you set the permissions of the .ssh directory and its files? The .ssh directory should be set to 0700 for example and authorized_keys should have 0600

hi Scrutinizer,

thanks for info. but I already tried with permission as indicated by you. but it is not working...

Tell us more about your systems.

Show us the permissions you have with

ls -ld ~/.ssh ; ls -l ~/.ssh

...on both the local and remote sides.

Try

ssh -v -v username@host

to see if it prints any more information.