[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Need command line to run a file 4 times

jackster the jackle

1/11/2008 1:48:00 PM

Hi Ruby Forum...

I have a script that I run every minute in cron to gather SNMP
statistics and put them in a DB.

Since CRON only goes down to one minute intervals and I'd rather not
change my code to loop so that I can poll every 15 seconds, is there a
way to run a ruby file from the command line and tell it to run the file
4 times?

something like this (which I know doesn't work)

do /usr/bin/SnmpPoll.rb * (4)

Thanks

jackster

http://jac...
--
Posted via http://www.ruby-....

12 Answers

Xavier Noria

1/11/2008 2:42:00 PM

0

On Jan 11, 2008, at 2:47 PM, jackster the jackle wrote:

> Since CRON only goes down to one minute intervals and I'd rather not
> change my code to loop so that I can poll every 15 seconds, is there a
> way to run a ruby file from the command line and tell it to run the
> file
> 4 times?

You mean something like this?

$ for x in 1 2 3 4; do echo $x; done
1
2
3
4

-- fxn



jackster the jackle

1/11/2008 4:00:00 PM

0

Xavier Noria wrote:
> You mean something like this?
>
> $ for x in 1 2 3 4; do echo $x; done
> 1
> 2
> 3
> 4
>
> -- fxn

Not exactly Xavier. I have a file (/usr/bin/snmp_poller.rb), when it
runs, it polls a network device and stores the SNMP data in the DB. I
currently have this running in CRON every minute. Without putting a loop
in my snmp_poller.rb code, I want to somehow tell CRON using a ruby
command line option, to run snmp_poller.rb 4 times.

I know there are a lot of command line, one liners to run ruby code and
I was hoping someone had one to do this.

thanks

jackster.mobi
--
Posted via http://www.ruby-....

Xavier Noria

1/11/2008 4:08:00 PM

0

On Jan 11, 2008, at 5:00 PM, jackster the jackle wrote:

> Xavier Noria wrote:
>> You mean something like this?
>>
>> $ for x in 1 2 3 4; do echo $x; done
>> 1
>> 2
>> 3
>> 4
>>
>> -- fxn
>
> Not exactly Xavier. I have a file (/usr/bin/snmp_poller.rb), when it
> runs, it polls a network device and stores the SNMP data in the DB. I
> currently have this running in CRON every minute. Without putting a
> loop
> in my snmp_poller.rb code, I want to somehow tell CRON using a ruby
> command line option, to run snmp_poller.rb 4 times.
>
> I know there are a lot of command line, one liners to run ruby code
> and
> I was hoping someone had one to do this.

Hmmm, but how is that different from chaging echo $x with your script?
No trying to push that shell loop, just trying to understand the goal.

-- fxn


jackster the jackle

1/11/2008 4:14:00 PM

0

Xavier Noria wrote:
> Hmmm, but how is that different from chaging echo $x with your script?
> No trying to push that shell loop, just trying to understand the goal.
>
> -- fxn

It's actually not different, I was just looking for another way to do it
for control purposes.

jackster.mobi
--
Posted via http://www.ruby-....

Siep Korteling

1/11/2008 4:29:00 PM

0

=
>
> It's actually not different, I was just looking for another way to do it
> for control purposes.
>
> jackster.mobi

from the commandline:

ruby -e '4.times{`/usr/bin/SnmpPoll.rb` ; sleep 15}'


regards,

Siep

--
Posted via http://www.ruby-....

Xavier Noria

1/11/2008 4:32:00 PM

0

On Jan 11, 2008, at 5:13 PM, jackster the jackle wrote:

> Xavier Noria wrote:
>> Hmmm, but how is that different from chaging echo $x with your
>> script?
>> No trying to push that shell loop, just trying to understand the
>> goal.
>>
>> -- fxn
>
> It's actually not different, I was just looking for another way to
> do it
> for control purposes.

Oh good.

Off the top of my head a possible approach would be:

ruby -e '4.times { load "path/to/file" }'

-- fxn


jackster the jackle

1/11/2008 5:13:00 PM

0

Xavier Noria wrote:
> Off the top of my head a possible approach would be:
>
> ruby -e '4.times { load "path/to/file" }'
>
> -- fxn


That is exactly what I was looking for, Xavier! Thanks alot, that worked
perfectly.

jackster.mobi
--
Posted via http://www.ruby-....

jackster the jackle

1/11/2008 6:01:00 PM

0

Siep Korteling wrote:
> =
>>
>> It's actually not different, I was just looking for another way to do it
>> for control purposes.
>>
>> jackster.mobi
>
> from the commandline:
>
> ruby -e '4.times{`/usr/bin/SnmpPoll.rb` ; sleep 15}'
>
>
> regards,
>
> Siep

Thanks for that added piece of information Siep, that might come in
handy for me.

jackster.mobi
--
Posted via http://www.ruby-....

jackster the jackle

1/11/2008 6:04:00 PM

0

My script is doing exactly what I want it to do now...but I see some
warnings in STDOUT:

warning: already initialized contstant <VARIABLE NAME HERE>

I think it's reporting this because ruby is looping through the file but
other than that, it's working fine.

Is there someway to fix this or at least prevent the warning from going
to the console?

thanks again

jackster.mobi
--
Posted via http://www.ruby-....

Carlos J. Hernandez

1/11/2008 7:10:00 PM

0

jacster:

You must be defining (assigning) the constant at one point in the
program flow, and
then defining again.
If the constant is in a loop, take it out.
I typically define all my constants within the first few lines at the
top of the file right after the require statements.

Ruby only warns that you're using a constant as a variable.
If you mean to use it as a variable, don't use capital letters.

-Carlos

On Sat, 12 Jan 2008 03:03:50 +0900, "jackster the jackle"
<contact@thirdorder.net> said:
> My script is doing exactly what I want it to do now...but I see some
> warnings in STDOUT:
>
> warning: already initialized contstant <VARIABLE NAME HERE>
>
> I think it's reporting this because ruby is looping through the file but
> other than that, it's working fine.
>
> Is there someway to fix this or at least prevent the warning from going
> to the console?
>
> thanks again
>
> jackster.mobi
> --
> Posted via http://www.ruby-....
>