GAV
GAV

Reputation: 1213

bash script using scp to transfer a file searched for

I've not had much experience with bash at all. The below script worked when I didn't use the find command and just scp straight from the file. But I'm trying to find and transfer a file which has todays d/m/y appended and transfer only this one after finding it.

Currently gives the error 'file not found' also not sure how to use variables in this situation, as I'm a PHP coder. Thanks

#!/usr/bin/expect -f

FILENAME = appendname_'.date +%d%m%Y;

spawn bash -c "scp 'find /www/reports/archives . -name 
$FILENAME.txt'    ftpdomain.com:/"

expect "password:"

send "pwaord\r"

expect "*\r"

expect "ok"

Upvotes: 2

Views: 156

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201537

I recommend you use ssh-keygen and install the key on your server, then you can use scp without having to provide a password through expect. To your question, you can use command substitution (bash supports $() and ``), something like

spawn bash -c "scp $(find /www/reports/archives -name $FILENAME.txt)  
        ftpdomain.com:/"

Upvotes: 1

Related Questions