Can ruby do a repeated Reboot test script

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

···

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

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

···

--
Jeff Peng
Email: jeffpeng@netzero.net
Skype: compuperson

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.

···

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.

--
Mark Hobley
Linux User: #370818 http://markhobley.yi.org/

Remembering of course to explicitly flush the file buffer of the status file and sync the filesystem before performing the reboot :slight_smile:

Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net

···

On 6 Feb 2010, at 11:10, Mark Hobley wrote:

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.

----
raise ArgumentError unless @reality.responds_to? :reason

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 :wink: Some do.

-dan

Eleanor McHugh wrote:

Remembering of course to explicitly flush the file buffer of the status file and sync the filesystem before performing the reboot :slight_smile:

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

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 ?

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

ryt! yrt! rty! ytr! try!

···

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

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

···

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 :slight_smile:

I'm astonished that the system reboot command does not do this!

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

Curious

----
raise ArgumentError unless @reality.responds_to? :reason

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

ryt! yrt! rty! ytr! try!

···

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

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.

···

On Saturday 06 February 2010 04:32:54 pm Eleanor McHugh wrote:

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 :slight_smile:
>
> 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...