How do I use a variable in an FTP shell script?
Using a handy script that I found for FTP-ing, I modified it to my own use, and it works, but too well, or too literally.
#!/bin/sh
HOST='10.0.1.110'
USER='myName'
PASSWD='myPass'
FILE='*.sql' # WILDCARD NOT WORKING - Takes literal string of '*.sql'
# Stripped unrelated code
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
prompt
binar开发者_如何转开发y
cd Desktop/SweepToDiskBK
mput /home/myAcct/SQLbackups/"$FILE" "$FILE"
quit
END_SCRIPT
exit
That is, the file(s) that gets 'put', is named *.sql
, and replaces any previous versions of it, instead of file1.sql
, file2.sql
, etc. In the original script, they were doing a put
, instead of an mput
, and with a single file names text.txt
. I've also tried changing the single quotes after FILE
, to double quotes, and got the same result. Can someone let me in on the 'trick' to using variables for CLI FTP-ing?
Thanks in advance, LO
I'd try this:
FILE=*.sql
without any quotes enabling wildcard expansion and:
mput /home/myAcct/SQLbackups/"$FILE"
with just one $FILE
But i think you can just do mput /home/myAcct/SQLbackups/$FILE
to mput *.sql
? Or if you need to put several files with put, then you need to do it one by one with some sort of a loop.
To check what the script does, change ftp -n $HOST
to cat
. Try these very commands in the plain ftp session. Do they work?
精彩评论