Find the answer to your Linux question:
Results 1 to 2 of 2
Hello, i want to copy a file from various accounts on a server, and save each file in different directories.Then i write a bash script : Code: #!/bin/bash FILE=$1 HOST=$2 ...
  1. #1
    Just Joined!
    Join Date
    Oct 2009
    Posts
    1

    Post Copy remote files with expect and scp

    Hello, i want to copy a file from various accounts on a server, and save each file in different directories.Then i write a bash script :
    Code:
    #!/bin/bash 
    FILE=$1
    HOST=$2
    IFS=: 
    while read LOGIN PASS 
    do 
    mkdir $LOGIN 
    expect -c " 
    spawn scp $LOGIN(AT)$HOST:programas/$FILE $LOGIN/$FILE 
    expect { 
    "password:" { send $PASS\r\n; interact } 
    eof { exit } 
    } " 
    done< iplogins

    I have a text file where i have the list of logins and passwords in the form:
    login1: pass1
    login2: pass2

    But the script copy only the file from the first login(sometimes don't copy anything) and stops in the first iteration of while... as if the expect have break of c/c++

    The code without the while works fine, but i want to copy the file from all accounts, not one by one.

  2. #2
    Linux Newbie tetsujin's Avatar
    Join Date
    Oct 2008
    Posts
    115
    Instead of using expect to send a password to scp, why not use an ssh key pair to bypass password authentication altogether?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...