Re: crontab hour range 6-midnight

2011-12-02 Thread Jochen Spieker
Bob Proulx:
> Jochen Spieker wrote:
>> Bob Proulx:
>>>
>>> Having a literal '~/' in there works for bash.  But it doesn't work
>>> for /bin/sh linked to dash for example.
>> 
>> Works here:
… snip
> But that doesn't have anything to do with PATH.  You didn't test PATH
> containing "~/" in it.  You tested cd with "~" as an option argument.
> Those are different things.

Thanks for the convincing demonstration. I never had expected that to
make a difference.

J.
-- 
I will not admit to failure even when I know I am terribly mistaken and
have offended others.
[Agree]   [Disagree]
 


signature.asc
Description: Digital signature


Re: crontab hour range 6-midnight

2011-12-02 Thread Bob Proulx
Bob Proulx wrote:
> Jochen Spieker wrote:
> > Bob Proulx:
> > > Having a literal '~/' in there works for bash.  But it doesn't work
> > > for /bin/sh linked to dash for example.
> > 
> > Works here:
> > 
> > $ exec /bin/dash
> > $ cd /
> > $ pwd
> > /
> > $ cd ~
> > $ pwd
> > /home/jrschulz
> 
> But that doesn't have anything to do with PATH.  You didn't test PATH
> containing "~/" in it.  You tested cd with "~" as an option argument.
> Those are different things.
> 
> If you want to test PATH with "~/" in it then here is a test for it.
> It must be two process layers deep.  It must launch a non-bash process
> which itself launches a process.  It must not be a bash script.

Silly me!  Here is an even simpler test.

  $ mkdir -p $HOME/bin

  $ cat >$HOME/bin/pathtrial1 <<\EOF
#!/bin/sh
echo hello from pathtrial1
EOF
  $ chmod a+x $HOME/bin/pathtrial1
  $ pathtrial1
  hello from pathtrial1

That sets up the test as before.  Then simply start up dash with that PATH.

I use 'env' here as the portable way to invoke a command with a
specified environment but avoiding shell aliases and so forth and
regardless of your shell being csh or some such.

  $ env PATH='~/bin:/usr/bin:/bin' /bin/dash

Then try calling programs from $HOME/bin.  They won't be found.

  $ pathtrial1
  /bin/dash: 1: pathtrial1: not found

  $ echo $PATH
  ~/bin:/usr/bin:/bin

Bob


signature.asc
Description: Digital signature


Re: crontab hour range 6-midnight

2011-12-02 Thread Bob Proulx
Jochen Spieker wrote:
> Bob Proulx:
> > Having a literal '~/' in there works for bash.  But it doesn't work
> > for /bin/sh linked to dash for example.
> 
> Works here:
> 
> $ exec /bin/dash
> $ cd /
> $ pwd
> /
> $ cd ~
> $ pwd
> /home/jrschulz

But that doesn't have anything to do with PATH.  You didn't test PATH
containing "~/" in it.  You tested cd with "~" as an option argument.
Those are different things.

If you want to test PATH with "~/" in it then here is a test for it.
It must be two process layers deep.  It must launch a non-bash process
which itself launches a process.  It must not be a bash script.

  $ mkdir -p $HOME/bin

  $ cat >$HOME/bin/pathtrial1 <<\EOF
#!/bin/sh
echo hello from pathtrial1
EOF
  $ chmod a+x $HOME/bin/pathtrial1
  $ pathtrial1
  hello from pathtrial1

  $ cat >$HOME/bin/pathtrial2 <<\EOF
#!/bin/dash
echo "PATH=$PATH"
type pathtrial1
pathtrial1
EOF
  $ chmod a+x $HOME/bin/pathtrial2
  $ pathtrial2
  
PATH=/home/rwp/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/sbin:/sbin
  pathtrial1 is /home/bob/bin/pathtrial1
  hello from pathtrial1

That will set up a small test case.  Be sure to quote the EOF and to
check that the variables were not expanded in the test case script and
that the quotes were included properly.  Otherwise they will have been
expanded when you created the script and the test case won't have been
created properly.

Then set up your crontab with PATH holding ~/bin in it as per the
discussion.  Then call pathtrial2 in your crontab.  This following will
do it.

  SHELL=/bin/bash
  PATH=~/bin:/usr/local/bin:/usr/bin:/bin:/usr/games
  * * * * *   pathtrial2

That will show the failure.  Cron will invoke pathtrial2 and since
SHELL is set to bash then bash will find pathtrial2 in $HOME/bin okay.
That first layer of invocation will work successfully.  But the
pathtrial2 script will try to find pathtrial1 on PATH and being a
/bin/dash script it will not interpret PATH with ~/ in it and will
fail to find pathtrial1.  Cron will email the output to you.

  PATH=~/bin:/usr/local/bin:/usr/bin:/bin:/usr/games
  pathtrial1: not found
  /home/rwp/bin/pathtrial2: 4: /home/rwp/bin/pathtrial2: pathtrial1: not found

This illustrates the failure.  It isn't the first shell from cron that
fails.  That shell is bash and it works okay.  It is children
processes of bash that fail since PATH contains ~/ in it and that
expansion is a bash specific extension.

Before someone thinks this is only a problem because /bin/sh is
symlinked to dash let me show an example using perl.  Using perl has
exactly the same problem.  Set up a pathtrial3 script so that it looks
like this:

  #!/usr/bin/perl -l
  print "PATH=$ENV{'PATH'}";
  print "%%>>" . `pathtrial1` . "<<%%";
  print $?;

Run that from the command line with a normal PATH.  You will get this
output:

  $ pathtrial3
  
PATH=/home/rwp/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/sbin:/sbin
  %%>>hello from pathtrial1
  <<%%
  0

That looks normal given the script, right?.  Then change the crontab
to call pathtrial3 instead of pathtrial2.  By email you should be
seeing this following output:

  PATH=~/bin:/usr/local/bin:/usr/bin:/bin:/usr/games
  %%>><<%%
  -1

The pathtrial1 script couldn't be found on PATH.  It failed.  It is
this second layer of processes which will fail if they can't find
their programs on PATH.  Perl scripts and other processes that need to
locate programs on PATH will not be expanding ~/ to be the $HOME
directory since that is a bash specific extension.  Those will fail.

Bob


signature.asc
Description: Digital signature


Re: crontab hour range 6-midnight

2011-12-02 Thread Jochen Spieker
Bob Proulx:
> Jochen Spieker wrote:
>> 
>> You still can use
>> 
>> PATH = "~/bin:/usr/local/bin:/usr/bin:/bin:/usr/games"
>> 
>> if the crontab belongs to the user 'rwp'.
> 
> Having a literal '~/' in there works for bash.  But it doesn't work
> for /bin/sh linked to dash for example.

Works here:

$ exec /bin/dash
$ cd /
$ pwd
/
$ cd ~
$ pwd
/home/jrschulz

J.
-- 
I wish I could do more to put the sparkle back into my marriage.
[Agree]   [Disagree]
 


signature.asc
Description: Digital signature


Re: crontab hour range 6-midnight

2011-12-01 Thread Bob Proulx
Bob Proulx wrote:
> Jochen Spieker wrote:
> > Bob Proulx:
> > >   # The default vixie-cron PATH is "/usr/bin:/bin", overriding the 
> > > environment.
> > >   PATH = "/home/rwp/bin:/usr/local/bin:/usr/bin:/bin:/usr/games"
> > 
> > You still can use
> > 
> > PATH = "~/bin:/usr/local/bin:/usr/bin:/bin:/usr/games"
> > 
> > if the crontab belongs to the user 'rwp'.
> 
> Having a literal '~/' in there works for bash.  But it doesn't work
> for /bin/sh linked to dash for example.  On Debian /bin/sh defaults to
> being linked to /bin/dash, not bash, these days and in that case using
> ~/ wouldn't work.
> 
> So I guess that if ~ is used in PATH then SHELL should also be set to
> bash too.  That combination is fine.  And then of course all of the
> other fun bash'isms on the command line would also work.

Ah...  But bash doesn't clean up the path for it's own children.  So
actually that does not work.  Or works only in a restricted subset.
Because if the command executed invokes other commands those other
commands will get PATH with a ~/ in it and unless they also decode
that syntax they might fail.

So beware.  Switched it back to the full path in PATH without the ~/
in it.  And should file a bug against the crontab(5) man page about
the problem too.

Bob


signature.asc
Description: Digital signature


Re: crontab hour range 6-midnight

2011-12-01 Thread Bob Proulx
Jochen Spieker wrote:
> Bob Proulx:
> >   # The default vixie-cron PATH is "/usr/bin:/bin", overriding the 
> > environment.
> >   PATH = "/home/rwp/bin:/usr/local/bin:/usr/bin:/bin:/usr/games"
> 
> You still can use
> 
> PATH = "~/bin:/usr/local/bin:/usr/bin:/bin:/usr/games"
> 
> if the crontab belongs to the user 'rwp'.

Having a literal '~/' in there works for bash.  But it doesn't work
for /bin/sh linked to dash for example.  On Debian /bin/sh defaults to
being linked to /bin/dash, not bash, these days and in that case using
~/ wouldn't work.

So I guess that if ~ is used in PATH then SHELL should also be set to
bash too.  That combination is fine.  And then of course all of the
other fun bash'isms on the command line would also work.

  SHELL=/bin/bash

Thanks for the hint!

Bob


signature.asc
Description: Digital signature


Re: crontab hour range 6-midnight

2011-12-01 Thread Jochen Spieker
Bob Proulx:
> 
>   # The default vixie-cron PATH is "/usr/bin:/bin", overriding the 
> environment.
>   PATH = "/home/rwp/bin:/usr/local/bin:/usr/bin:/bin:/usr/games"

You still can use

PATH = "~/bin:/usr/local/bin:/usr/bin:/bin:/usr/games"

if the crontab belongs to the user 'rwp'.

J.
-- 
Nothing is as I planned it.
[Agree]   [Disagree]
 


signature.asc
Description: Digital signature


Re: crontab hour range 6-midnight

2011-12-01 Thread Bob Proulx
Jochen Spieker wrote:
> But beware that you probably need to use /full/path/to/my-script. $PATH
> is probably not what you expect.

Debian uses Vixie Cron which has some nice extensions, such as that
"*/10" you were using.  It also allows you to set PATH for all of your
cron commands.  I always have this in my crontab:

  # The default vixie-cron PATH is "/usr/bin:/bin", overriding the environment.
  PATH = "/home/rwp/bin:/usr/local/bin:/usr/bin:/bin:/usr/games"
  # Setting PATH is a vixie-cron extension.
  # Variables are not expanded.  Quotes are optional.

But note that you can't use variables such as $HOME and must set a
hard string value.

Bob


signature.asc
Description: Digital signature


Re: crontab hour range 6-midnight

2011-12-01 Thread Nicolas Bercher

Darac Marjal a écrit :

On Thu, Dec 01, 2011 at 12:19:06PM +0100, Jochen Spieker wrote:

Nicolas Bercher:

I'd like use set up a crontab rule from 6 am to midnight, and crontab(5) 
mentions:
  field  allowed values
  hour   0-23

Then, I tried something like:
  */10 6-0 * * 1-5 my-script

Using this, cron should execute my-script on 06:10, 06:20 … 23:50, 00:00, 00:10 
…
00:50. What you probably want is

*/10 6-23 * * * my-script


In addition to the above, remember that it's possible to supply lists to
cron fields. If you want to span midnight, you probably want something
like:

  */10 0,6-23 * * * my-script

Though this will run every 10 mins in the hours 00:00, 06:00, 07:00
etc. Again, probably not what you want. 6-23 will probably be best.


Thanks you two, things get clearer now because I was thinking about
numbers as boundaries instead of durations.

So you were both right, what fits my needs the best is probably
"*/10 6-23 * * 1-5"

Nicolas


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Archive: http://lists.debian.org/4ed785d8.7070...@yahoo.fr



Re: crontab hour range 6-midnight

2011-12-01 Thread Darac Marjal
On Thu, Dec 01, 2011 at 12:19:06PM +0100, Jochen Spieker wrote:
> Nicolas Bercher:
> > 
> > I'd like use set up a crontab rule from 6 am to midnight, and crontab(5) 
> > mentions:
> >   field  allowed values
> >   hour   0-23
> > 
> > Then, I tried something like:
> >   */10 6-0 * * 1-5 my-script
> 
> Using this, cron should execute my-script on 06:10, 06:20 … 23:50, 00:00, 
> 00:10 …
> 00:50. What you probably want is
> 
> */10 6-23 * * * my-script

In addition to the above, remember that it's possible to supply lists to
cron fields. If you want to span midnight, you probably want something
like:

  */10 0,6-23 * * * my-script

Though this will run every 10 mins in the hours 00:00, 06:00, 07:00
etc. Again, probably not what you want. 6-23 will probably be best.

-- 
Darac Marjal


signature.asc
Description: Digital signature


Re: crontab hour range 6-midnight

2011-12-01 Thread Jochen Spieker
Nicolas Bercher:
> 
> I'd like use set up a crontab rule from 6 am to midnight, and crontab(5) 
> mentions:
>   field  allowed values
>   hour   0-23
> 
> Then, I tried something like:
>   */10 6-0 * * 1-5 my-script

Using this, cron should execute my-script on 06:10, 06:20 … 23:50, 00:00, 00:10 
…
00:50. What you probably want is

*/10 6-23 * * * my-script

But beware that you probably need to use /full/path/to/my-script. $PATH
is probably not what you expect.

> As a more generic question: can we define rules that spans hours,
> days, etc. writing ranges "n-m" where m Cant' find such answers (except by experiencing a lot... and waiting a lot!).

Just try the it with minutes instead of hours.

> Moreover, crontab is happily "installing new crontab" when I use such
> rules, but they don't seem to be treated at all.

You should your job in /var/log/syslog.

J.
-- 
I wish I was gay.
[Agree]   [Disagree]
 


signature.asc
Description: Digital signature


crontab hour range 6-midnight

2011-12-01 Thread Nicolas Bercher
Hi,

I'd like use set up a crontab rule from 6 am to midnight, and crontab(5) 
mentions:
  field  allowed values
  hour   0-23

Then, I tried something like:
  */10 6-0 * * 1-5 my-script

Can this be correct or do I face an overlap issue? (I mean since 0 is the 
begining of the *next* hour).

As a more generic question: can we define rules that spans hours, days, etc. 
writing ranges "n-m" where mhttp://lists.debian.org/1322734000.69849.yahoomail...@web28505.mail.ukl.yahoo.com