Skip to main content
single typo-fix
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265

This isn't doing what you want:

set FILEPATH1 $1

Tcl (and expect) don't use the shell-style $1, $2, ... way of accessing the command line arguments. You want to use the global $argv list:

set FILEPATH1 [lindex $argv 0]

Also, your spawn call is incorrect. sh will be looking for a file named "scp $FILEPATH1 $USER@$HOST:/destination/files". You dontdon't need a shell to spawn scp:

spawn scp $FILEPATH1 $USER@$HOST:/destination/files

Now, where are USER and HOST coming from? Are they environment variables? If so:

spawn scp $FILEPATH1 $env(USER)@$env(HOST):/destination/files

And, you're not waiting for the transfer to actually complete before your script exits. Do this:

expect password:
send "$pass\r"
set timeout -1
expect eof

I'm assuming that you're only prompted for the password once. If you have to enter it multiple times, then

expect {
    password: {
        send "$pass\r"
        set timeout -1
        exp_continue
    }
    eof
}

This isn't doing what you want:

set FILEPATH1 $1

Tcl (and expect) don't use the shell-style $1, $2, ... way of accessing the command line arguments. You want to use the global $argv list:

set FILEPATH1 [lindex $argv 0]

Also, your spawn call is incorrect. sh will be looking for a file named "scp $FILEPATH1 $USER@$HOST:/destination/files". You dont need a shell to spawn scp:

spawn scp $FILEPATH1 $USER@$HOST:/destination/files

Now, where are USER and HOST coming from? Are they environment variables? If so:

spawn scp $FILEPATH1 $env(USER)@$env(HOST):/destination/files

And, you're not waiting for the transfer to actually complete before your script exits. Do this:

expect password:
send "$pass\r"
set timeout -1
expect eof

I'm assuming that you're only prompted for the password once. If you have to enter it multiple times, then

expect {
    password: {
        send "$pass\r"
        set timeout -1
        exp_continue
    }
    eof
}

This isn't doing what you want:

set FILEPATH1 $1

Tcl (and expect) don't use the shell-style $1, $2, ... way of accessing the command line arguments. You want to use the global $argv list:

set FILEPATH1 [lindex $argv 0]

Also, your spawn call is incorrect. sh will be looking for a file named "scp $FILEPATH1 $USER@$HOST:/destination/files". You don't need a shell to spawn scp:

spawn scp $FILEPATH1 $USER@$HOST:/destination/files

Now, where are USER and HOST coming from? Are they environment variables? If so:

spawn scp $FILEPATH1 $env(USER)@$env(HOST):/destination/files

And, you're not waiting for the transfer to actually complete before your script exits. Do this:

expect password:
send "$pass\r"
set timeout -1
expect eof

I'm assuming that you're only prompted for the password once. If you have to enter it multiple times, then

expect {
    password: {
        send "$pass\r"
        set timeout -1
        exp_continue
    }
    eof
}
Source Link
glenn jackman
  • 88.5k
  • 16
  • 124
  • 179

This isn't doing what you want:

set FILEPATH1 $1

Tcl (and expect) don't use the shell-style $1, $2, ... way of accessing the command line arguments. You want to use the global $argv list:

set FILEPATH1 [lindex $argv 0]

Also, your spawn call is incorrect. sh will be looking for a file named "scp $FILEPATH1 $USER@$HOST:/destination/files". You dont need a shell to spawn scp:

spawn scp $FILEPATH1 $USER@$HOST:/destination/files

Now, where are USER and HOST coming from? Are they environment variables? If so:

spawn scp $FILEPATH1 $env(USER)@$env(HOST):/destination/files

And, you're not waiting for the transfer to actually complete before your script exits. Do this:

expect password:
send "$pass\r"
set timeout -1
expect eof

I'm assuming that you're only prompted for the password once. If you have to enter it multiple times, then

expect {
    password: {
        send "$pass\r"
        set timeout -1
        exp_continue
    }
    eof
}