Menu

Automatic remote files copy

Help
epicJules
2009-10-28
2013-05-02
  • epicJules

    epicJules - 2009-10-28

    Hello, i want to copy a file from various accounts on a server, and save each file in differents directories.Then i write a bash script :

      
    <pre><code>#!/bin/bash
    FILE=$1
    HOST=$2
    IFS=:
    while read LOGIN PASS
    do
    mkdir $LOGIN
    expect -c "
    spawn scp $LOGIN@$HOST:programas/$FILE $LOGIN/$FILE
    expect {
            "*password:*" { send $PASS\r\n; interact }
            eof { exit }
      }
    "
    done< iplogins.txt

    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.

     
  • ender

    ender - 2009-10-28

    Can you try creating the script differently? Instead of having a bash script use expect to do this, make an expect script to do it. Have expect open the text file of logins and passwords, have expect loop through them and copy the files.

     

Log in to post a comment.