Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

reboot for NT/2K

by idnopheq (Chaplain)
on Apr 23, 2001 at 14:07 UTC ( #74671=sourcecode: print w/ replies, xml ) Need Help??

Category: NT Admin
Author/Contact Info idnopheq
Description: reboot -- restart the operating system

reboot restarts the hardware and operating system.

Although reboot can be run by the super-user at any time, shutdown is normally used first to warn all users logged in of the impending loss of service. See shutdown for details.

#!/usr/local/bin/perl -w
#-*-perl-*-
#
#
#

use strict;
use Win32;
use Getopt::Std;
use vars qw ( %Option );

my ($VERSION) = '$Revision: 1.0 $' =~ /([.\d]+)/;

my $warnings = 0;

# Print a usuage message on a unknown option.

$SIG {__WARN__} = sub {
    if (substr ($_ [0], 0, 14) eq "Unknown option") {die "Usage"};
    require File::Basename;
    $0 = File::Basename::basename ($0);
    $warnings = 1;
    warn "$0: @_";
};

$SIG {__DIE__} = sub {
    require File::Basename;
    $0 = File::Basename::basename ($0);
    if (substr ($_ [0], 0,  5) eq "Usage") {
        die <<EOF;
$0 (NT Perl bin utils) $VERSION
$0 [ -a | -q ] [ -h ]
EOF
    }
    die "$0: @_";
};

# Get the options.

getopts ( 
     'haq',
      \%Option 
    );                    # -h, -q & -a take no option

die "Usage" if ( $Option{'h'} || scalar keys %Option > 1 );

my $Server = "";

if ( $Option{'a'} ) {
  Win32::AbortSystemShutdown (
                  $Server
                 ) 
      or die "$^E\n";
  exit;
}

my $Message = "Reboot initiated by " . getlogin . "\n";
my $Timeout = $Option{'q'} || "60";
my $ForceClose = $Option{'q'} || "0";
my $Reboot = "6";

Win32::InitiateSystemShutdown (
                   $Server,
                   $Message,
                   $Timeout,
                   $ForceClose,
                   $Reboot - 5
                  ) 
  or die "$^E\n";

=pod

=head1 NAME

B<reboot> -- restart the operating system

=head1 SYNOPSIS

B<reboot> [ -a ]

B<reboot> [ -q ]

=head1 DESCRIPTION

B<reboot> restarts the hardware and operating system.

Although B<reboot> can be run by the super-user at any time, B<shutdow
+n> is normally used first to warn all users logged in of the impendin
+g loss of service. See B<shutdown> for details.

=head2 OPTIONS

=over 4

=item -a

Abort the B<reboot> command.

=item -q

Quick. Reboot quickly without notifying logged-in users or saving data
+.

=item -h

Display syntax.

=back

=head1 EXAMPLES

In the following example, B<reboot> is being executed on host foo in 6
+0 seconds.

example# reboot

In the example below, a quick reboot is requested immediately.

example# reboot -q

The following example aborts the above.

example# reboot -a

=head1 ENVIRONMENT

The working of B<reboot> is not influenced by any environment variable
+s.

=head1 BUGS

B<reboot> suffers from no known bugs at this time.

=head1 STANDARDS

It does not make sense to talk about standards in a B<reboot> manual p
+age.

=head1 REVISION HISTORY

    reboot
    Revision 1.0  2000/06/22 08:35:57  idnopheq
    Initial revision

=head1 AUTHOR

The Perl implementation of B<reboot> was written by Dexter Coffin, I<i
+dnopheq@home.com>.

=head1 COPYRIGHT and LICENSE

This program is copyright by Dexter Coffin 2000.

This program is free and open software. You may use, copy, modify, dis
+tribute,
and sell this program (and any modified variants) in any way you wish,
provided you do not restrict others from doing the same.

=head1 SEE ALSO

=for html
<a href="shutdown.html">shutdown</a><p>

=head1 NEXT TOPIC

=cut

Comment on reboot for NT/2K
Download Code

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://74671]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (20)
As of 2014-10-20 18:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (89 votes), past polls