Re: silly bash scripting question - minor error correction

2008-12-09 Thread Amos Shapira
2008/12/8 Ehud Karni <[EMAIL PROTECTED]>:
> I had an error, I did not notice that one of your variable includes ":".
> Change my separator character to % in the 3rd solution like this:
>
> rsync="/usr/bin/rsync%-navHz%--delete%--delay-updates%--bwlimit=256%-e%ssh -i 
> /root/rsync.id"
> local=/mnt/data/html/minicpan
> copyto="test01:$local" # here you use :
> IFS="%"# use only % (not space) to separate tokens
> $rsync $local/ $copyto/# you can use % or space for extra arguments
>
> Ehud.

Thanks.

I'm not clear on what's the advantage of this approach over eval. Can
you explain it to me?

Cheers,

--Amos

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Re: silly bash scripting question - minor error correction

2008-12-07 Thread Ehud Karni
I had an error, I did not notice that one of your variable includes ":".
Change my separator character to % in the 3rd solution like this:

rsync="/usr/bin/rsync%-navHz%--delete%--delay-updates%--bwlimit=256%-e%ssh -i 
/root/rsync.id"
local=/mnt/data/html/minicpan
copyto="test01:$local" # here you use :
IFS="%"# use only % (not space) to separate tokens
$rsync $local/ $copyto/# you can use % or space for extra arguments

Ehud.


--
 Ehud Karni   Tel: +972-3-7966-561  /"\
 Mivtach - Simon  Fax: +972-3-7966-667  \ /  ASCII Ribbon Campaign
 Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
 http://www.mvs.co.il  FAX:  1-815-5509341  / \
 GnuPG: 98EA398D Better Safe Than Sorry

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Re: silly bash scripting question

2008-12-07 Thread Ehud Karni
On Fri, 5 Dec 2008 09:58:34 +1100, Amos Shapira wrote:
>
> I've been doing shell programming for years but this got me stomped
> (simplified version):
>
> rsync="/usr/bin/rsync -navHz --delete --delay-updates --bwlimit=256 -e
> 'ssh -i /root/rsync.id'"
> local=/mnt/data/html/minicpan
> copyto="test01:$local"
> $rsync $local/ $copyto/
>
> When I execute this script with "sh -vx" the final lines are:
>
> $rsync $local/ $copyto/
> + /usr/bin/rsync -navHz --delete --delay-updates --bwlimit=256 -e
> ''\''ssh' -i '/root/rsync.id'\''' /mnt/data/html/minicpan/
> test01:/mnt/data/html/minicpan/
> Missing trailing-' in remote-shell command.
> rsync error: syntax or usage error (code 1) at main.c(361) [sender=3.0.4]
>
> It looks like the shell splits the value of "$ssh" into words and adds
> quoting around them.
>
> The rsync command line I'd like to see is:
>
> /usr/bin/rsync -navHz --delete --delay-updates --bwlimit=256 -e ''ssh
> -i /root/rsync.id'' /mnt/data/html/minicpan/
> test01:/mnt/data/html/minicpan/


I don't think you want double apostrophes but a single quote.

1. You can solve your problem by putting the ssh command in RSYNC_RSH like this
   export RSYNC_RSH="ssh -i /root/rsync.id" instead of using -e.

2 You can put the ssh command in a variable (no eval or functions):

SSH="ssh -i /root/rsync.id"
rsync="/usr/bin/rsync -navHz --delete --delay-updates --bwlimit=256 -e"
local=/mnt/data/html/minicpan
copyto="test01:$local"
$rsync "$SSH" $local/ $copyto/ ## note the quotes around $SSH

3. You can change the IFS variable to use : (or another character)
instead of space, something like this (try it, I did):

rsync="/usr/bin/rsync:-navHz:--delete:--delay-updates:--bwlimit=256:-e:ssh -i 
/root/rsync.id"
local=/mnt/data/html/minicpan
copyto="test01:$local"
IFS=":"# use only : (not space) to separate tokens
$rsync $local/ $copyto/# you can use : or space for extra arguments

Note. Be warned not to change the IFS. If you must do it (like in my 3rd
solution), remember to set it back to what it was as soon as possible (its
default - not be changed - value is " \t\n").

So do:  SVIFS="$IFS"
IFS="new-value"

IFS="$SVIFS"   # the quotes are essential

Ehud.


--
 Ehud Karni   Tel: +972-3-7966-561  /"\
 Mivtach - Simon  Fax: +972-3-7966-667  \ /  ASCII Ribbon Campaign
 Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
 http://www.mvs.co.il  FAX:  1-815-5509341  / \
 GnuPG: 98EA398D Better Safe Than Sorry

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Re: silly bash scripting question

2008-12-04 Thread guy keren


Amos Shapira wrote:

2008/12/5 guy keren <[EMAIL PROTECTED]>:

this is a great way to write "write-only" code. often-times, the simple
solution, even if it is uglier, is the one that'll be easier to maintain
later on.


I think the external-script solution is uglier because it's yet
another file to keep track of in a heap of scripts and config files.


and regarding the function - this is completely different from using a
variable - because of the way the shell performs its expansion work. the
main problem is that the shell works in a non-recursive expansion order
(i.e. it knows how to expand 7 or 8 things, but it always expands them in
the same order). this is most likely why an extra eval helped - it causes
the shell to expand everything twice. unfortunately, those evals sometimes
add other side effects that break the expression, and they cause code to be
un-maintainable.


Can you give a full example of how would you rewrite the sample code
to use a shell function instead of eval?

Code maintainability is very important to me.


i don't have how to test this now, but basically, i would try to write a 
shell function named 'blabla', which contains a single line of code - 
ssh -i /root/rsync.id


and supply the name of this function to the '-e' flag of rsync - and see 
if this works. i'm not sure it will - but you can still try this.


if this does work - you may place the definition of this function just 
above the rsync line - and you won't have to use an extra file.


--guy



Thanks,

--Amos

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]




=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Re: silly bash scripting question

2008-12-04 Thread Amos Shapira
2008/12/5 guy keren <[EMAIL PROTECTED]>:
> this is a great way to write "write-only" code. often-times, the simple
> solution, even if it is uglier, is the one that'll be easier to maintain
> later on.

I think the external-script solution is uglier because it's yet
another file to keep track of in a heap of scripts and config files.

>
> and regarding the function - this is completely different from using a
> variable - because of the way the shell performs its expansion work. the
> main problem is that the shell works in a non-recursive expansion order
> (i.e. it knows how to expand 7 or 8 things, but it always expands them in
> the same order). this is most likely why an extra eval helped - it causes
> the shell to expand everything twice. unfortunately, those evals sometimes
> add other side effects that break the expression, and they cause code to be
> un-maintainable.

Can you give a full example of how would you rewrite the sample code
to use a shell function instead of eval?

Code maintainability is very important to me.

Thanks,

--Amos

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Re: silly bash scripting question

2008-12-04 Thread guy keren

Amos Shapira wrote:

2008/12/5 guy keren <[EMAIL PROTECTED]>:

there are certain constructs of quoting that you simply cannot do with a
shell.

put your 'ssh -i /root/rsync.id' command in a script file, and supply the
script file in the '-e' flag of rsync.


Yes I though about that - but it's very ugly, especially if it's a
side-script and the operation has to be repeated from different
scripts.


you may also pus the 'ssh -i ...' in a shell function - it'll work just the
same.


Though about this too but this all started when the "ssh..." part was
in its own variable (for easier configurability), so I'm not sure
it'll help with the quoting.

Someone else off list suggested "eval" - just putting "eval" in front
of the "rsync" call made things work as I wanted :).


this is a great way to write "write-only" code. often-times, the simple 
solution, even if it is uglier, is the one that'll be easier to maintain 
later on.


and regarding the function - this is completely different from using a 
variable - because of the way the shell performs its expansion work. the 
main problem is that the shell works in a non-recursive expansion order 
(i.e. it knows how to expand 7 or 8 things, but it always expands them 
in the same order). this is most likely why an extra eval helped - it 
causes the shell to expand everything twice. unfortunately, those evals 
sometimes add other side effects that break the expression, and they 
cause code to be un-maintainable.


but of-course, it's up to you to decide what solution is more suitable 
for you.


--guy



Thanks,

--Amos

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]




=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Re: silly bash scripting question

2008-12-04 Thread Amos Shapira
2008/12/5 Omer Zak <[EMAIL PROTECTED]>:
> I checked the expressions, using 'echo $whatever' in my bash, whose
> version string is:
> GNU bash, version 3.1.17(1)-release (i486-pc-linux-gnu)
> Copyright (C) 2005 Free Software Foundation, Inc.
>
> All behaved without extra quote marks or whatever.
>
> So, Amos - please let us know which shell and version did you use for
> 'sh'.

# bash --version
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

This is an up to date centos 5.2

The "echo" indeed shows things as they are expected, but:

e=echo
$e $rsync $local/ $copyto/

gives:

e=echo
+ e=echo
$e $rsync $local/ $copyto/
+ echo /usr/bin/rsync -navHz --delete --delay-updates --bwlimit=256 -e
''\''ssh' -i '/root/rsync.id'\''' /mnt/data/html/minicpan/
test01:/mnt/data/html/minicpan/
/usr/bin/rsync -navHz --delete --delay-updates --bwlimit=256 -e 'ssh
-i /root/rsync.id' /mnt/data/html/minicpan/
test01:/mnt/data/html/minicpan/

And maybe that's what the eval does, i.e. it's equivalent to:

eval `$e $rsync $local/ $copyto/`

Which works right (but then - the echo and `` are redundant).

Cheers,

--Amos

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Re: silly bash scripting question

2008-12-04 Thread Amos Shapira
2008/12/5 guy keren <[EMAIL PROTECTED]>:
>
> there are certain constructs of quoting that you simply cannot do with a
> shell.
>
> put your 'ssh -i /root/rsync.id' command in a script file, and supply the
> script file in the '-e' flag of rsync.

Yes I though about that - but it's very ugly, especially if it's a
side-script and the operation has to be repeated from different
scripts.

>
> you may also pus the 'ssh -i ...' in a shell function - it'll work just the
> same.

Though about this too but this all started when the "ssh..." part was
in its own variable (for easier configurability), so I'm not sure
it'll help with the quoting.

Someone else off list suggested "eval" - just putting "eval" in front
of the "rsync" call made things work as I wanted :).

Thanks,

--Amos

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Re: silly bash scripting question

2008-12-04 Thread Omer Zak
I checked the expressions, using 'echo $whatever' in my bash, whose
version string is:
GNU bash, version 3.1.17(1)-release (i486-pc-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

All behaved without extra quote marks or whatever.

So, Amos - please let us know which shell and version did you use for
'sh'.

--- Omer

On Fri, 2008-12-05 at 09:58 +1100, Amos Shapira wrote:
> I've been doing shell programming for years but this got me stomped
> (simplified version):
> 
> rsync="/usr/bin/rsync -navHz --delete --delay-updates --bwlimit=256 -e
> 'ssh -i /root/rsync.id'"
> local=/mnt/data/html/minicpan
> copyto="test01:$local"
> $rsync $local/ $copyto/
> 
> When I execute this script with "sh -vx" the final lines are:
> 
> $rsync $local/ $copyto/
> + /usr/bin/rsync -navHz --delete --delay-updates --bwlimit=256 -e
> ''\''ssh' -i '/root/rsync.id'\''' /mnt/data/html/minicpan/
> test01:/mnt/data/html/minicpan/
> Missing trailing-' in remote-shell command.
> rsync error: syntax or usage error (code 1) at main.c(361) [sender=3.0.4]
> 
> It looks like the shell splits the value of "$ssh" into words and adds
> quoting around them.
> 
> The rsync command line I'd like to see is:
> 
> /usr/bin/rsync -navHz --delete --delay-updates --bwlimit=256 -e ''ssh
> -i /root/rsync.id'' /mnt/data/html/minicpan/
> test01:/mnt/data/html/minicpan/
> 
> But whatever I tried so far playing with single quotes or back-slashes
> I haven't managed to make the shell do that.
> 
> What am I missing?
-- 
Philip Machanick: "caution: if you write code like this, immediately
after you are fired the person assigned to maintaining your code after
you leave will resign"
My own blog is at http://www.zak.co.il/tddpirate/

My opinions, as expressed in this E-mail message, are mine alone.
They do not represent the official policy of any organization with which
I may be affiliated in any way.
WARNING TO SPAMMERS:  at http://www.zak.co.il/spamwarning.html


=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Re: silly bash scripting question

2008-12-04 Thread guy keren


there are certain constructs of quoting that you simply cannot do with a 
shell.


put your 'ssh -i /root/rsync.id' command in a script file, and supply 
the script file in the '-e' flag of rsync.


you may also pus the 'ssh -i ...' in a shell function - it'll work just 
the same.


--guy

Amos Shapira wrote:

Hi,

I've been doing shell programming for years but this got me stomped
(simplified version):

rsync="/usr/bin/rsync -navHz --delete --delay-updates --bwlimit=256 -e
'ssh -i /root/rsync.id'"
local=/mnt/data/html/minicpan
copyto="test01:$local"
$rsync $local/ $copyto/

When I execute this script with "sh -vx" the final lines are:

$rsync $local/ $copyto/
+ /usr/bin/rsync -navHz --delete --delay-updates --bwlimit=256 -e
''\''ssh' -i '/root/rsync.id'\''' /mnt/data/html/minicpan/
test01:/mnt/data/html/minicpan/
Missing trailing-' in remote-shell command.
rsync error: syntax or usage error (code 1) at main.c(361) [sender=3.0.4]

It looks like the shell splits the value of "$ssh" into words and adds
quoting around them.

The rsync command line I'd like to see is:

/usr/bin/rsync -navHz --delete --delay-updates --bwlimit=256 -e ''ssh
-i /root/rsync.id'' /mnt/data/html/minicpan/
test01:/mnt/data/html/minicpan/

But whatever I tried so far playing with single quotes or back-slashes
I haven't managed to make the shell do that.

What am I missing?

Thanks,

--Amos

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]




=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



silly bash scripting question

2008-12-04 Thread Amos Shapira
Hi,

I've been doing shell programming for years but this got me stomped
(simplified version):

rsync="/usr/bin/rsync -navHz --delete --delay-updates --bwlimit=256 -e
'ssh -i /root/rsync.id'"
local=/mnt/data/html/minicpan
copyto="test01:$local"
$rsync $local/ $copyto/

When I execute this script with "sh -vx" the final lines are:

$rsync $local/ $copyto/
+ /usr/bin/rsync -navHz --delete --delay-updates --bwlimit=256 -e
''\''ssh' -i '/root/rsync.id'\''' /mnt/data/html/minicpan/
test01:/mnt/data/html/minicpan/
Missing trailing-' in remote-shell command.
rsync error: syntax or usage error (code 1) at main.c(361) [sender=3.0.4]

It looks like the shell splits the value of "$ssh" into words and adds
quoting around them.

The rsync command line I'd like to see is:

/usr/bin/rsync -navHz --delete --delay-updates --bwlimit=256 -e ''ssh
-i /root/rsync.id'' /mnt/data/html/minicpan/
test01:/mnt/data/html/minicpan/

But whatever I tried so far playing with single quotes or back-slashes
I haven't managed to make the shell do that.

What am I missing?

Thanks,

--Amos

=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]