On Monday 09 October 2006 10:04, Sasha Dolgy wrote:
> I'm currently trying to write a simple bash shell script that
> recursively loops through a directory and for each directory entry
> will mirror the contents to a remote backup server.  In principal
> everything works fine when i step through the commands step by step.

Which shell are you using? (echo $SHELL)

> One big issue I am having however is integrating the commands into a
> shell script.
>
> One of the limits of shell scripting, is that by placing single quotes
> ( ' ) within a shell script, variable expansion doesn't occur between
> the single quotes ..

This is not a limitation, it is a feature. Use double quotes if you want 
variable expansion.

> #!/bin/sh
> backupDirectory="/tmp/somedir/for/backups"

Here you don't need double quotes.

> for backupDir in `ls -1 ${backupDirectory}/`;
>      msg="attempting backup on ${backupDir}: -- [ "
>      cmdString="mirror -R ${backupDirectory}/${backupDir}
> backups/${backupDir}" # no keyword expansion

Yes, you have variable expansion here..

>      ${ftpProgram} -c 'open -e \"${cmdString}\" ${siteUrl}'

.. but here you don't.
Try this:
${ftpProgram} -c "open -e '${cmdString}' ${siteUrl}"

(Note: untested!)

>      # no errors , return code of 0 but doesn't transfer files remotely
>      # ${ftpProgram} -c \'open -e \"${cmdString}\" ${siteUrl}\'
>
>      cmdStatus=${?}
>       if [ ${cmdStatus} -gt 0 ]; then

What if the return status is -1?

>              msg="${msg} failed ] --"
>       else
>               msg="${msg} success ] --"
>       fi
> done
>
> The above is what I have.  The variables aren't expanded.  When I
> escape the single quotes with a backslash ( \ ) the command is shown
> properly and returns a return code of 0 -- ( $? == 0 ) . . however,
> nothing is actually done.  I can confirm this when I run it command
> line with the single quotes escaped.
>
> Now, I realize that my problems are more limitations with the shell
> scripting environment I'm using rather then lftp, however, I'm
> emailing in  hope that someone on this list knows of another way I can
> work around this?

Again. This is not limitations, but misusage. If you want to improve your 
shell scripting abilities I recommend trying google: abs bash. This will give 
you The Advanced Bash-Scripting Guide. Chapter 5.1 I believe should clear 
some of your misunderstandings out.

I'm sure you can do all of this using lftp only... Try using the recursive 
mirror command directly on the backupDirectory.

-- 
Bjørge

Reply via email to