Forum: Ruby Can ruby do a repeated Reboot test script

Posted by Ham Baba (hambaba)
on 2010-02-06 09:52
Just want to write a ruby script that reboots the computer for 10
repeated times. Is it possible? I appriciate any help.
Posted by Jeff Peng (Guest)
on 2010-02-06 10:30
(Received via mailing list)
在 2010-02-06六的 17:52 +0900,Ham Baba写道:
> Just want to write a ruby script that reboots the computer for 10
> repeated times. Is it possible? I appriciate any help.


You may want to write a status file for the rebooting count.
For example:

rcdFile="/tmp/reboot.rcd"

times = 0
if File.file? rcdFile
    File.open(rcdFile) do |f|
        times = f.read.to_i
    end
else
    File.open(rcdFile,"w") do |f|
        f.write(times)
    end
end

times += 1
File.open(rcdFile,"w") do |f|
    f.write(times)
end

if times <= 10
    system("reboot")
end


Then run this script from crontab or system init scripts.

HTH.
Posted by Mark Hobley (Guest)
on 2010-02-06 12:18
(Received via mailing list)
Ham Baba <hamid_rasoulian@yahoo.com> wrote:
> Just want to write a ruby script that reboots the computer for 10
> repeated times. Is it possible? I appriciate any help.

Ensure that your system is configured in such a manner that members of
"shutdown" can reboot the system. Create a startup script to run the 
rebooter
as a member of the shutdown group. From within the ruby software: create 
a
counter" file if one does not exist, setting the count to 10. Use the 
count
that the file contains. If the count is zero, then exit because the 
system has
already rebooted 10 times, otherwise decrement the count and "shell out" 
to
the reboot command.

Mark.
Posted by Eleanor McHugh (Guest)
on 2010-02-06 13:44
(Received via mailing list)
On 6 Feb 2010, at 11:10, Mark Hobley wrote:
> the reboot command.
Remembering of course to explicitly flush the file buffer of the status 
file and sync the filesystem before performing the reboot :)


Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net
----
raise ArgumentError unless @reality.responds_to? :reason
Posted by Ian Hobson (Guest)
on 2010-02-06 22:56
(Received via mailing list)
Eleanor McHugh wrote:
> Remembering of course to explicitly flush the file buffer of the status file and sync the filesystem before performing the reboot :)
>
>   
I'm astonished that the system reboot command does not do this!

Closing the file is certainly necessary. Isn't the rest unnecessary?

Curious

Ian
Posted by Eleanor McHugh (Guest)
on 2010-02-06 23:34
(Received via mailing list)
On 6 Feb 2010, at 21:55, Ian Hobson wrote:
> Eleanor McHugh wrote:
>> Remembering of course to explicitly flush the file buffer of the status file and sync the filesystem before performing the reboot :)
>>  
> I'm astonished that the system reboot command does not do this!
> 
> Closing the file is certainly necessary. Isn't the rest unnecessary?
> 
> Curious

If journalling's enabled on the filesystem it's *probably* unnecessary, 
but let's just say I've been stung enough times to be naturally 
cautious...


Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net
----
raise ArgumentError unless @reality.responds_to? :reason
Posted by David Masover (Guest)
on 2010-02-07 02:14
(Received via mailing list)
On Saturday 06 February 2010 04:32:54 pm Eleanor McHugh wrote:
> 
> If journalling's enabled on the filesystem it's *probably* unnecessary, but
>  let's just say I've been stung enough times to be naturally cautious...

I guess it depends on the system you're on -- when I type 'reboot', my 
system
shuts down, including killing all processes (giving them time to flush 
their
buffers), then flushing the filesystem (twice) before actually 
rebooting.

Now, if you did something like 'reboot -f', it would instantly reboot, 
and a
journaling filesystem wouldn't save you. Sure, your filesystem would be 
fine,
but your data might not, especially if you only had half of it written, 
with
the other half in a buffer somewhere.
Posted by unknown (Guest)
on 2010-02-08 17:52
(Received via mailing list)
Jeff Peng <jeffpeng@netzero.net> writes:

> You may want to write a status file for the rebooting count.
> For example:
>
> rcdFile="/tmp/reboot.rcd"

If you put the staus file in /tmp, make sure your system doesn't clear
that directory on each boot ;-)  Some do.


-dan
Posted by Raveendran .P (jazzezravi)
on 2010-02-10 11:23
Hi,

Step 1 --> Create 1 text file like

        sample.txt
         Content:

            10

Step 2 --> Ruby program read the content from File. So its 10 now. 
Before going to restart the machine write the file content as : 9 and 
save the file.


Step 2 help --> How to reboot machine ?

http://raveendran.wordpress.com/2008/04/22/console-commands-in-rubywindows/



Step 3 --> Before run the program PUT the rb file into SETUP 
environment.



I think it will works. Please update once after tried in this way.


Thanks
Raveendran
http://raveendran.wordpress.com

ryt! yrt! rty! ytr!  try!

Posted by Raveendran .P (jazzezravi)
on 2010-02-10 11:25
 Hi,

I have missed to mention step 5 in previous conversation.


Step 5 --> When the file contains content == 1 then read and delete the 
file. So next time it wont read the file and also wont run.

Sorry for the inconvenience.


Thanks
Raveendran
http://raveendran.wordpress.com

ryt! yrt! rty! ytr!  try!
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.