in reply to Create a folder/file and reboot the machine and check for the created file/folder on the location.
in thread reboot a system (machine or server) multiple times with perl script

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
  • Comment on Re: Create a folder/file and reboot the machine and check for the created file/folder on the location.
  • Download Code

Replies are listed 'Best First'.
Re^2: Create a folder/file and reboot the machine and check for the created file/folder on the location.
by GotToBTru (Prior) on Mar 13, 2015 at 18:50 UTC

    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.