I want to run a particular script every 3 minutes. I would do this
using crontab in Linux, but I am having trouble getting that to work.
The script works fine from the Windows or Linux command line, however.
I thought it might be easier to add some code to the end of the script
that tells it to sleep for three mins and then start at the beginning.
I want to run a particular script every 3 minutes. I would do this
using crontab in Linux, but I am having trouble getting that to work.
The script works fine from the Windows or Linux command line, however.
I thought it might be easier to add some code to the end of the script
that tells it to sleep for three mins and then start at the beginning.
In practice I would say this is a bad idea. What if you start this on a server and forget about it? Then, some day down the road, the process starts failing for whatever reason, and some poor admin is left wondering whether or not it's safe to kill the process. Call me paranoid.
Better to figure out why it's failing under cron. The most likely causes, in my experience, tend to be environment variable issues and bad assumptions about what Dir.pwd is.
Regards,
Dan
···
ara.t.howard@noaa.gov wrote:
On Wed, 7 Jun 2006, Hunter Walker wrote:
I want to run a particular script every 3 minutes. I would do this
using crontab in Linux, but I am having trouble getting that to work.
The script works fine from the Windows or Linux command line, however.
I thought it might be easier to add some code to the end of the script
that tells it to sleep for three mins and then start at the beginning.
Not to be contrarian, but pickaxe page 180 says that ARGV[0] is not the
name of the program (unlike in C). There's other stuff I don't get
about your snippet as well.
Why ["ruby" + ARGV]??? Seems like you're using + to add an array to a
string? Can you explain it for us newbies?
Working from Pickaxe page 180 I would have come up with something like:
sleep 180 # obvious
pieces = [ruby, $0].concat(ARGV) # $0 is program name
exec pieces.join(' ') # to string and execute it
BTW, many rubyist's would, I think, stick the .join(' ') on the end of
the array composition, like this:
exec [ruby, $0].concat(ARGV).join(' ')
Is there a move away from such Perlish pursuits, or are you still
considered a "Sheila" if you split things like this up into more easily
understandable pieces?
dan is right of course. i didn't say it was a good idea - but you can do it
-a
···
On Wed, 7 Jun 2006, Daniel Berger wrote:
sleep 180
exec ["ruby" + ARGV].join(' ')
-a
In practice I would say this is a bad idea. What if you start this on a server and forget about it? Then, some day down the road, the process starts failing for whatever reason, and some poor admin is left wondering whether or not it's safe to kill the process. Call me paranoid.
Better to figure out why it's failing under cron. The most likely causes, in my experience, tend to be environment variable issues and bad assumptions about what Dir.pwd is.
Regards,
Dan
--
suffering increases your inner strength. also, the wishing for suffering
makes the suffering disappear.
- h.h. the 14th dali lama
Not to be contrarian, but pickaxe page 180 says that ARGV[0] is not the
name of the program (unlike in C). There's other stuff I don't get
about your snippet as well.
Why ["ruby" + ARGV]??? Seems like you're using + to add an array to a
string? Can you explain it for us newbies?
Working from Pickaxe page 180 I would have come up with something like:
sleep 180 # obvious
pieces = [ruby, $0].concat(ARGV) # $0 is program name
exec pieces.join(' ') # to string and execute it
BTW, many rubyist's would, I think, stick the .join(' ') on the end of
the array composition, like this:
exec [ruby, $0].concat(ARGV).join(' ')
Is there a move away from such Perlish pursuits, or are you still
considered a "Sheila" if you split things like this up into more easily
understandable pieces?
Not to be contrarian, but pickaxe page 180 says that ARGV[0] is not the
name of the program (unlike in C). There's other stuff I don't get
about your snippet as well.
Why ["ruby" + ARGV]??? Seems like you're using + to add an array to a
string? Can you explain it for us newbies?
On Wed, 7 Jun 2006, Jeff Pritchard wrote:
--
suffering increases your inner strength. also, the wishing for suffering
makes the suffering disappear.
- h.h. the 14th dali lama
While all these options work, in a production environment I wouldnt
feel right with a scheduling system of some sort. autosys/cron/at etc.
···
On 6/6/06, Hunter <walkerhunter@gmail.com> wrote:
Jeff Pritchard wrote:
> Not to be contrarian, but pickaxe page 180 says that ARGV[0] is not the
> name of the program (unlike in C). There's other stuff I don't get
> about your snippet as well.
> Why ["ruby" + ARGV]??? Seems like you're using + to add an array to a
> string? Can you explain it for us newbies?
>
> Working from Pickaxe page 180 I would have come up with something like:
> sleep 180 # obvious
> pieces = [ruby, $0].concat(ARGV) # $0 is program name
> exec pieces.join(' ') # to string and execute it
>
> BTW, many rubyist's would, I think, stick the .join(' ') on the end of
> the array composition, like this:
> exec [ruby, $0].concat(ARGV).join(' ')
>
> Is there a move away from such Perlish pursuits, or are you still
> considered a "Sheila" if you split things like this up into more easily
> understandable pieces?
>
> thanks,
> jp
>
> unknown wrote:
>> On Wed, 7 Jun 2006, Hunter Walker wrote:
>>
>>>
>>> --
>>> Posted via http://www.ruby-forum.com/\.
>>
>> sleep 180
>> exec ["ruby" + ARGV].join(' ')
>>
>> -a
While all these options work, in a production environment I wouldnt
feel right with a scheduling system of some sort. autosys/cron/at etc.
On 6/6/06, Hunter <walkerhunter@gmail.com> wrote:
> Jeff Pritchard wrote:
> > Not to be contrarian, but pickaxe page 180 says that ARGV[0] is not the
> > name of the program (unlike in C). There's other stuff I don't get
> > about your snippet as well.
> > Why ["ruby" + ARGV]??? Seems like you're using + to add an array to a
> > string? Can you explain it for us newbies?
> >
> > Working from Pickaxe page 180 I would have come up with something like:
> > sleep 180 # obvious
> > pieces = [ruby, $0].concat(ARGV) # $0 is program name
> > exec pieces.join(' ') # to string and execute it
> >
> > BTW, many rubyist's would, I think, stick the .join(' ') on the end of
> > the array composition, like this:
> > exec [ruby, $0].concat(ARGV).join(' ')
> >
> > Is there a move away from such Perlish pursuits, or are you still
> > considered a "Sheila" if you split things like this up into more easily
> > understandable pieces?
> >
> > thanks,
> > jp
> >
> > unknown wrote:
> >> On Wed, 7 Jun 2006, Hunter Walker wrote:
> >>
> >>>
> >>> --
> >>> Posted via http://www.ruby-forum.com/\.
> >>
> >> sleep 180
> >> exec ["ruby" + ARGV].join(' ')
> >>
> >> -a
>
> I just got an error when I tried the code below:
>
> exec ["ruby" + ARGV].join(' ')
>
> I'll try the code you suggested, JP. Thanks!
>
> --
> Posted via http://www.ruby-forum.com/\.
>
The first trick is that you need to build the necessary $PATH and
other environment for your application. So I'd start with:
% env > runner.sh
I'd then add your script to the bottom:
% echo `which ruby` myscript.rb >> runner.sh
Then, edit runner.sh to get rid of environment variables you *know*
you don't need and pare down the ones that you do need to the minimum
level required to run myscript.rb with Ruby.
-austin
···
On 6/6/06, Hunter Walker <walkerhunter@gmail.com> wrote:
So I should create a shell script that runs the command? Can you
provide an example? Sorry, I am new at this...if you couldn't alreay
tell.
puts buf unless exitstatus == 0 or exitstatus == 42
exit exitstatus
this script runs it's command line under a bash login shell - so you'll have
your entire 'normal' environment available. additionally it mops up any
output __unless__ the program fails - in which case it dumps it back out.
this is because cron emails it's user the output of any program - this way you
only get emails when programs fail.
regards.
-a
···
On Wed, 7 Jun 2006, Hunter Walker wrote:
So I should create a shell script that runs the command? Can you provide an
example? Sorry, I am new at this...if you couldn't alreay tell.
--
suffering increases your inner strength. also, the wishing for suffering
makes the suffering disappear.
- h.h. the 14th dali lama