Unix Technical Forum

crontab referencing nonexistant file(system)

This is a discussion on crontab referencing nonexistant file(system) within the comp.unix.solaris forums, part of the Solaris Operating System category; --> Greetings all, I'm wondering if anyone has found a more elegant way of solving this problem. The situation: I ...


Go Back   Unix Technical Forum > Unix Operating Systems > Solaris Operating System > comp.unix.solaris

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-12-2008, 05:59 AM
pbeckhelm@gmail.com
 
Posts: n/a
Default crontab referencing nonexistant file(system)

Greetings all,

I'm wondering if anyone has found a more elegant way of solving this
problem.

The situation:

I have two hosts that are SAN attached, but only the active (VxVM)
node can actually mount the filesystems on the SAN. I have a user on
both systems that needs to run a script via cron periodically and I
want to make sure the scripts that that user is running are the exact
same scripts.

My solution:

I have put the scripts on the SAN storage, and since only the active
node can "see" the scripts, only the cron jobs on that node will
succeed. My testing shows that the only ill effect thus far is a
"rc=1" entry for that job in the /var/cron/log on the passive node.

--

I'd like to be sure that I'm doing this as elegantly and as
efficiently as possible and not opening myself up to some kind of
problem in so doing. Anyone have any ideas on how to do this better?

Cheers,

pb

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-12-2008, 05:59 AM
Giorgos Keramidas
 
Posts: n/a
Default Re: crontab referencing nonexistant file(system)

On Mon, 08 Oct 2007 23:12:46 -0000, pbeckhelm@gmail.com wrote:
> Greetings all,
>
> I'm wondering if anyone has found a more elegant way of solving this
> problem.
>
> The situation:
>
> I have two hosts that are SAN attached, but only the active (VxVM)
> node can actually mount the filesystems on the SAN. I have a user on
> both systems that needs to run a script via cron periodically and I
> want to make sure the scripts that that user is running are the exact
> same scripts.
>
> My solution:
>
> I have put the scripts on the SAN storage, and since only the active
> node can "see" the scripts, only the cron jobs on that node will
> succeed. My testing shows that the only ill effect thus far is a
> "rc=1" entry for that job in the /var/cron/log on the passive node.
>
> I'd like to be sure that I'm doing this as elegantly and as
> efficiently as possible and not opening myself up to some kind of
> problem in so doing. Anyone have any ideas on how to do this better?


You could always use something like:

5 * * * * /root/scripts/run.sh /path/to/real/script

and keep a local copy of `/root/scripts/run.sh' on each node, which
contains something like:

#!/bin/sh

if test ! -x $1 ; then
exit 0
fi

shift
exec $1 "$@"

But that sounds like a bit of overkill, and you still get to keep a
local copy of `run.sh' on each node :-/

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-12-2008, 05:59 AM
Darren Dunham
 
Posts: n/a
Default Re: crontab referencing nonexistant file(system)

Giorgos Keramidas <keramida@ceid.upatras.gr> wrote:
> You could always use something like:
>
> 5 * * * * /root/scripts/run.sh /path/to/real/script
>
> and keep a local copy of `/root/scripts/run.sh' on each node, which
> contains something like:
>
> #!/bin/sh
>
> if test ! -x $1 ; then
> exit 0
> fi
>
> shift
> exec $1 "$@"
>
> But that sounds like a bit of overkill, and you still get to keep a
> local copy of `run.sh' on each node :-/


Might as well just do that in the crontab:

0 0 * * * [ -x /path/to/script ] && /path/to/script


--
Darren Dunham ddunham@taos.com
Senior Technical Consultant TAOS http://www.taos.com/
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-12-2008, 05:59 AM
Giorgos Keramidas
 
Posts: n/a
Default Re: crontab referencing nonexistant file(system)

On Tue, 09 Oct 2007 00:21:22 GMT, ddunham@taos.com (Darren Dunham) wrote:
>Giorgos Keramidas <keramida@ceid.upatras.gr> wrote:
>> You could always use something like:
>>
>> 5 * * * * /root/scripts/run.sh /path/to/real/script
>>
>> and keep a local copy of `/root/scripts/run.sh' on each node, which
>> contains something like:
>>
>> #!/bin/sh
>>
>> if test ! -x $1 ; then
>> exit 0
>> fi
>>
>> shift
>> exec $1 "$@"
>>
>> But that sounds like a bit of overkill, and you still get to keep a
>> local copy of `run.sh' on each node :-/

>
> Might as well just do that in the crontab:
>
> 0 0 * * * [ -x /path/to/script ] && /path/to/script


Indeed, but depending on the `/bin/sh' implementation, the return status
of the first part the return code may still be non-zero. That's what I
was trying to avoid by:

if test ! -x $1 ; then
exit 0
fi

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-12-2008, 05:59 AM
Henry Townsend
 
Posts: n/a
Default Re: crontab referencing nonexistant file(system)

Giorgos Keramidas wrote:
> On Tue, 09 Oct 2007 00:21:22 GMT, ddunham@taos.com (Darren Dunham) wrote:
>> Giorgos Keramidas <keramida@ceid.upatras.gr> wrote:
>>> You could always use something like:
>>>
>>> 5 * * * * /root/scripts/run.sh /path/to/real/script
>>>
>>> and keep a local copy of `/root/scripts/run.sh' on each node, which
>>> contains something like:
>>>
>>> #!/bin/sh
>>>
>>> if test ! -x $1 ; then
>>> exit 0
>>> fi
>>>
>>> shift
>>> exec $1 "$@"
>>>
>>> But that sounds like a bit of overkill, and you still get to keep a
>>> local copy of `run.sh' on each node :-/

>> Might as well just do that in the crontab:
>>
>> 0 0 * * * [ -x /path/to/script ] && /path/to/script

>
> Indeed, but depending on the `/bin/sh' implementation, the return status
> of the first part the return code may still be non-zero. That's what I
> was trying to avoid by:
>
> if test ! -x $1 ; then
> exit 0
> fi
>


That's why my shell coding paradigm is to always prefer the following
syntax:

[ ! -x /path/to/script ] || /path/to/script

even though it's a little less clear to novices, it always leaves $? in
the correct state. This in turn allows you to run scripts in "set -e"
mode or with a trap on error, depending on shell flavor, resulting in
more robust tools.

HT
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-12-2008, 05:59 AM
Gerry Sinkiewicz
 
Posts: n/a
Default Re: crontab referencing nonexistant file(system)


<pbeckhelm@gmail.com> wrote in message
news:1191885166.257268.200940@19g2000hsx.googlegro ups.com...
> Greetings all,
>
> I'm wondering if anyone has found a more elegant way of solving this
> problem.
>
> The situation:
>
> I have two hosts that are SAN attached, but only the active (VxVM)
> node can actually mount the filesystems on the SAN. I have a user on
> both systems that needs to run a script via cron periodically and I
> want to make sure the scripts that that user is running are the exact
> same scripts.
>
> My solution:
>
> I have put the scripts on the SAN storage, and since only the active
> node can "see" the scripts, only the cron jobs on that node will
> succeed. My testing shows that the only ill effect thus far is a
> "rc=1" entry for that job in the /var/cron/log on the passive node.
>
> --
>
> I'd like to be sure that I'm doing this as elegantly and as
> efficiently as possible and not opening myself up to some kind of
> problem in so doing. Anyone have any ideas on how to do this better?
>
> Cheers,
>
> pb
>


Your solution is mine too in just this situation, no ill affects on the
results, but some of the others
who responded have some neat ideas. I will study them and use if possible.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 01-12-2008, 05:59 AM
pbeckhelm@gmail.com
 
Posts: n/a
Default Re: crontab referencing nonexistant file(system)

On Oct 8, 5:21 pm, ddun...@taos.com (Darren Dunham) wrote:
>
> Might as well just do that in the crontab:
>
> 0 0 * * * [ -x /path/to/script ] && /path/to/script
>
> --
> Darren Dunham ddun...@taos.com
> Senior Technical Consultant TAOS http://www.taos.com/
> Got some Dr Pepper? San Francisco, CA bay area
> < This line left intentionally blank to confuse you.


I'm thinking that this is the most elegant way to do this, if for no
reason other than to make it explicitly clear to the reader that this
check is being done. In the way I'm currently doing it, we're relying
on cron to do this check, and I'd rather not do that (partly because I
don't want to try and predict how cron will react when something
breaks).

Can anyone see any problem with having cron do this checking?

pb

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 01-12-2008, 05:59 AM
Henry Townsend
 
Posts: n/a
Default Re: crontab referencing nonexistant file(system)

pbeckhelm@gmail.com wrote:
> On Oct 8, 5:21 pm, ddun...@taos.com (Darren Dunham) wrote:
>> Might as well just do that in the crontab:
>>
>> 0 0 * * * [ -x /path/to/script ] && /path/to/script
>>
>> --
>> Darren Dunham ddun...@taos.com
>> Senior Technical Consultant TAOS http://www.taos.com/
>> Got some Dr Pepper? San Francisco, CA bay area
>> < This line left intentionally blank to confuse you.

>
> I'm thinking that this is the most elegant way to do this, if for no
> reason other than to make it explicitly clear to the reader that this
> check is being done. In the way I'm currently doing it, we're relying
> on cron to do this check, and I'd rather not do that (partly because I
> don't want to try and predict how cron will react when something
> breaks).
>
> Can anyone see any problem with having cron do this checking?


There's no problem with cron doing the checking but I think you're
missing the point I made above. This:

0 0 * * * [ ! -x /path/to/script ] || /path/to/script

is more elegant, or at least better, than:

0 0 * * * [ -x /path/to/script ] && /path/to/script

Because the && formulation returns an error condition in the case that
the path doesn't exist. If you wanted that error condition you could
have just blindly done the exec in the first place, which is where we
came in.

HT
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 01-12-2008, 05:59 AM
pbeckhelm@gmail.com
 
Posts: n/a
Default Re: crontab referencing nonexistant file(system)

On Oct 10, 10:56 am, Henry Townsend <henry.towns...@not.here> wrote:
> pbeckh...@gmail.com wrote:
> > On Oct 8, 5:21 pm, ddun...@taos.com (Darren Dunham) wrote:
> >> Might as well just do that in the crontab:

>
> >> 0 0 * * * [ -x /path/to/script ] && /path/to/script

>
> >> --
> >> Darren Dunham ddun...@taos.com
> >> Senior Technical Consultant TAOS http://www.taos.com/
> >> Got some Dr Pepper? San Francisco, CA bay area
> >> < This line left intentionally blank to confuse you.

>
> > I'm thinking that this is the most elegant way to do this, if for no
> > reason other than to make it explicitly clear to the reader that this
> > check is being done. In the way I'm currently doing it, we're relying
> > on cron to do this check, and I'd rather not do that (partly because I
> > don't want to try and predict how cron will react when something
> > breaks).

>
> > Can anyone see any problem with having cron do this checking?

>
> There's no problem with cron doing the checking but I think you're
> missing the point I made above. This:
>
> 0 0 * * * [ ! -x /path/to/script ] || /path/to/script
>
> is more elegant, or at least better, than:
>
> 0 0 * * * [ -x /path/to/script ] && /path/to/script
>
> Because the && formulation returns an error condition in the case that
> the path doesn't exist. If you wanted that error condition you could
> have just blindly done the exec in the first place, which is where we
> came in.
>
> HT


You're absolutely right. I think the preservation of the error code
is the right practice.

pb

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 01-12-2008, 05:59 AM
Giorgos Keramidas
 
Posts: n/a
Default Re: crontab referencing nonexistant file(system)

On Tue, 09 Oct 2007 12:15:39 -0400, Henry Townsend <henry.townsend@not.here> wrote:
>Giorgos Keramidas wrote:
>>> Might as well just do that in the crontab:
>>>
>>> 0 0 * * * [ -x /path/to/script ] && /path/to/script

>>
>> Indeed, but depending on the `/bin/sh' implementation, the return status
>> of the first part the return code may still be non-zero. That's what I
>> was trying to avoid by:
>>
>> if test ! -x $1 ; then
>> exit 0
>> fi
>>

>
> That's why my shell coding paradigm is to always prefer the following
> syntax:
>
> [ ! -x /path/to/script ] || /path/to/script
>
> even though it's a little less clear to novices, it always leaves $? in
> the correct state. This in turn allows you to run scripts in "set -e"
> mode or with a trap on error, depending on shell flavor, resulting in
> more robust tools.


Oh, heh! Neat trick, thanks :-)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:07 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com