in reply to reboot a system (machine or server) multiple times with perl script

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.

  • Comment on Create a folder/file and reboot the machine and check for the created file/folder on the location.

Replies are listed 'Best First'.
Re: Create a folder/file and reboot the machine and check for the created file/folder on the location.
by Corion (Patriarch) on Mar 13, 2015 at 11:25 UTC
Re: Create a folder/file and reboot the machine and check for the created file/folder on the location.
by marto (Cardinal) on Mar 13, 2015 at 11:22 UTC
Re: Create a folder/file and reboot the machine and check for the created file/folder on the location.
by james28909 (Deacon) on Mar 13, 2015 at 13:28 UTC
    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
        Apologies, ofcourse i meant boot drive. But in windows, my boot drive is my boot partition, because it is a 512gb ssd unpartitioned.

        Either way the point was to write and/or modify a file per reboot.

        well the o.s here is ubuntu.