I am writing a script to scp some files but need to pass file location through the user or another script as an argument
#!/usr/bin/expect
set FILEPATH1 $1
spawn sh "scp $FILEPATH1 $USER@$HOST:/destination/files"
set pass "pass123"
expect {
password: {send "$pass\r"; exp_continue}
}
also tried this before the spawn and before the #!/usr/bin/expect
FILEPATH1=$1
Best Answer
This isn't doing what you want:
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: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:Now, where are USER and HOST coming from? Are they environment variables? If so:
And, you're not waiting for the transfer to actually complete before your script exits. Do this:
I'm assuming that you're only prompted for the password once. If you have to enter it multiple times, then