irthiza90 has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I'm a newbee to perl. I badly need your help in writing a script such a way that it reboots the machine multiple times at the start up. Can anyone please help, Thank you.

  • Comment on reboot a system (machine or server) multiple times with perl script

Replies are listed 'Best First'.
Re: reboot a system (machine or server) multiple times with perl script
by hippo (Archbishop) on Mar 13, 2015 at 11:41 UTC
    reboots the machine multiple times at the start up

    I have to say that this sounds like a terrible idea. Please explain why you think that this is desirable because it looks very much like an XY Problem.

Re: reboot a system (machine or server) multiple times with perl script
by choroba (Cardinal) on Mar 13, 2015 at 10:28 UTC
    What operating system does the machine have?
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      It's ubuntu

        There are various ways to automatically start a script on ubuntu. See http://askubuntu.com/questions/814/how-to-run-scripts-on-start-up

        This script will be restarted each time, so you have to leave information about what to do next on your system.

        Like writing to a file before rebooting and reading the status after restart.

        If availability matters you'll need another machine monitoring the process.

        BTW: Plz do not repost your question again!

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)

        PS: Je suis Charlie!

      is it possible ? , I mean i have tried pulling in the command system('reboot') with loop statments but none seem to be working, it reboots once but the loop is not functional.

        Once the system reboots, the script is no longer running. You have to leave some kind of persistent information for the system to iterate the next step, probably create a file somewhere. You also have to configure the system to check for the information upon start-up.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        Rebooting the machine WILL stop your running script. You'll have to set things up so that the script gets restarted on the next reboot.
Create a folder/file and reboot the machine and check for the created file/folder on the location.
by irthiza90 (Novice) on Mar 13, 2015 at 11:19 UTC

    Hi monks, am a newbee to perl, i have gone nuts trying to solve this, i want to Create a folder/file, auto reboot the machine and check for the created file/folder on the location. creating files and folders is a stuff to deal with but the second part rebooting and checking for the given file location is a tricky part. Please help me with this.Thank you.

      Best thing i know to do would be to program how many times you want it to reboot, then write the reboot attempt number to a file on the boot partition. psuedocode
      use warnings; use strict; open $my file, '<', "C:/reboot_attempts"; read $file, my $reboot_number, 1; if ($reboot_number == 0){ open my $file, '>', 'reboot_attempts'; print $file '1'; close $file; #reboot machine; } if ($reboot_number == 1){ open my $file, '>', 'reboot_attempts'; print $file '2'; close $file; #reboot machine; } if ($reboot_number == 2){ open my $file, '>', 'reboot_attempts'; print $file '3'; close $file; #reboot machine; } if ($reboot_number == 3){ open my $file, '>', 'reboot_attempts'; print $file '4'; close $file; #reboot machine; } if ($reboot_number == 4){ open my $file, '>', 'reboot_attempts'; print $file '5'; close $file; #reboot machine; } if ($reboot_number == 5){ open my $file, '>', 'reboot_attempts'; print $file '0'; #exit; }
      I am sure this can be improved greatly, but if you put in there the reboot code, it should be ok. The key is to set this up as a task that will run on boot. so you may need to use a batch file to run the script, or even make the script into an exe. Otherwise i am unsure on how you would actually execute the code on boot

        I don't think you know what a boot partition is. Suggesting that a novice alter his boot partition is tantamount to suggesting he play Russian Roulette with all chambers loaded. Perhaps you meant to say root directory (although where the file resides doesn't really matter).

        use warnings; use strict; my $max_attempts = 5; # for windows, replace cat with type my $reboot_number = `cat reboot_attempts` || 0; if ($reboot_number++ < $max_attempts) { `echo $reboot_number > reboot_attempts`; print "Rebooting...\n"; # code to make computer reboot here }
        Dum Spiro Spero