Please use ***
[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do
not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.
I'm not sure I can address the actual problem posted, but I'd like to comment on the script itself.
To start with, I take it that "
$LSCRIPT" is the name of a temporary file? What is "
$ARCHIVE"? The file to be transferred? Is it just one file, or can it contain multiple entries (in which case you should be using an array)?
My main concern is that you should really never hard-code usernames and passwords into a script. Not only do you do that here, but you then immediately
echo them into another text file, so now you have
two copies of them floating around!
One way to (relatively) safely handle passwords in scripts is to store them in a separate file that's only readable to the user running the script. Then have the script
source that file to import the values.
e.g. make a file that looks like this, in the user's home directory. Set it so that only the user has read permission for it.
Code:
# This file contains the username and password for
# the lftp command in my script.
my_user=username
my_pass=password
Note that the contents should be in the standard variable-setting syntax.
Then in the script, use something like this:
Code:
if [[ -r "$HOME/passwdfile.txt" ]]; then
. "$HOME/passwdfile.txt"
else
echo "Password file unreadable. Aborting." >&2
exit 1
fi
This will import the variables named "
$my_user" and "
$my_pass" for use in your script.
Next, a big warning:
QUOTE ALL OF YOUR VARIABLE EXPANSIONS. You should never leave the quotes off a parameter expansion unless you explicitly want the resulting string to be word-split by the shell and possible globbing patterns expanded. This is a vitally important concept in scripting, so train yourself to do it correctly now. You can learn about the exceptions later.
http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes
Also, since environment variables are generally all upper-case, it's recommended practice to keep your own user variables in lower-case or mixed-case to help differentiate them.
Finally, the external file probably isn't necessary, at least not for the command shown above. At the very least you can use a named pipe or
process substitution instead of the file.
Code:
# store the commands in an array variable first, for convenience.
# (each line needs to be quoted so that it gets set as a single entry):
lsscript=(
"open 10.10.1.55 -u $my_user,$my_pass"
"put -E $ARCHIVE"
)
# run lftp using printf on the array to create a simulated file.
/user/bin/lftp --log="$LOGFILE" -f <( printf '%s\n' "${lsscript[@]}" )
I imagine though that
lftp can read the commands directly from stdin? If so, then you should be able to just use a simple
here document instead.
Code:
# run lftp using a heredoc to send it the commands through stdin.
/user/bin/lftp --log="$LOGFILE" <<-SCRIPT
open 10.10.1.55 -u $my_user,$my_pass
put -E $ARCHIVE
SCRIPT
Note that using the extra hyphen in the "
<<-" means that it will strip off any leading
tab characters from the contents. This allows you to indent it for readability without worrying about affecting the contents.
Also notice that this is one of those places where you should NOT quote variables. Everything between the herdoc's end flags remains unparsed by the shell, with the exception of parameter/command expansion and the initial tab feature just mentioned.