Can ruby do a repeated Reboot test script

H

Ham Baba

Just want to write a ruby script that reboots the computer for 10
repeated times. Is it possible? I appriciate any help.
 
J

Jeff Peng

在 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.
 
M

Mark Hobley

Ham Baba said:
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.
 
E

Eleanor McHugh

=20
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. =46rom within the ruby software: = create a=20
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=20
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
 
I

Ian Hobson

Eleanor said:
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
 
E

Eleanor McHugh

I'm astonished that the system reboot command does not do this!
=20
Closing the file is certainly necessary. Isn't the rest unnecessary?
=20
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
 
D

David Masover

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.
 
D

dan

Jeff Peng said:
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
 
R

Raveendran Perumalsamy

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!
 
R

Raveendran Perumalsamy

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,185
Messages
2,570,992
Members
47,586
Latest member
DLWKathie7

Latest Threads

Top