Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
shutdown/reboot script in Perl for N3200
#1
Here's a short Perl script to shutdown or reboot a N3200 running v3 of the firmware. It does not rely on ssh or telnet access but interacts with the webserver. When executed with a name starting with shutdown, it does that, otherwise it does a reboot. Substitute your admin password and NAS address where indicated. It requires the Perl module WWW::Mechanize which may or may not be installed on your machine.

Code:
#!/usr/bin/perl -w

use strict;
use File::Basename;
use WWW::Mechanize;

my $action = (basename($0) =~ /shutdown.*/) ? 'shutdown' : 'reboot';

my $username = 'admin';
my $password = 'thepassword';
my $login_url = 'http://nasaddress/adm/login.php';
my $shutdown_url = 'http://nasaddress/adm/setmain.php?fun=setreboot';

# login to Thecus
my $mech = WWW::Mechanize->new(noproxy => 1);
$mech->agent_alias('Linux Mozilla');
$mech->post($login_url, {
        eplang          => 'english',
        p_user          => $username,
        p_pass          => $password,
        username        => $username,
        pwd             => $password,
        action          => 'login',
        option          => 'com_extplorer'
        }
);
die unless ($mech->success);
$mech->post($shutdown_url, {
        action          => $action
        }
);
my $content = $mech->content(format => 'text');
my $status = ($content =~ /The NAS has shut down|The system takes approximately 100 seconds to boot up/);
exit ($status ? 0 : 1);

It took me a while to work out because of the Javascript used. I use it to shutdown the NAS after a backup.

Have fun.
Reply
#2
Here's a short Perl script to shutdown or reboot a N3200 running v3 of the firmware. It does not rely on ssh or telnet access but interacts with the webserver. When executed with a name starting with shutdown, it does that, otherwise it does a reboot. Substitute your admin password and NAS address where indicated. It requires the Perl module WWW::Mechanize which may or may not be installed on your machine.

Code:
#!/usr/bin/perl -w

use strict;
use File::Basename;
use WWW::Mechanize;

my $action = (basename($0) =~ /shutdown.*/) ? 'shutdown' : 'reboot';

my $username = 'admin';
my $password = 'thepassword';
my $login_url = 'http://nasaddress/adm/login.php';
my $shutdown_url = 'http://nasaddress/adm/setmain.php?fun=setreboot';

# login to Thecus
my $mech = WWW::Mechanize->new(noproxy => 1);
$mech->agent_alias('Linux Mozilla');
$mech->post($login_url, {
        eplang          => 'english',
        p_user          => $username,
        p_pass          => $password,
        username        => $username,
        pwd             => $password,
        action          => 'login',
        option          => 'com_extplorer'
        }
);
die unless ($mech->success);
$mech->post($shutdown_url, {
        action          => $action
        }
);
my $content = $mech->content(format => 'text');
my $status = ($content =~ /The NAS has shut down|The system takes approximately 100 seconds to boot up/);
exit ($status ? 0 : 1);

It took me a while to work out because of the Javascript used. I use it to shutdown the NAS after a backup.

Have fun.
Reply
#3
Hi kenyap,

Thank you so much for sharing this tip. Smile

Regards,
John, Mar 24 '14
Reply
#4
What about E-SATA? Didn't test that, but should work allready for that functionality isn't it?
Reply
#5
What about E-SATA? Didn't test that, but should work allready for that functionality isn't it?
Reply
#6
Thanks for your post Smile
Reply
#7
Thanks for your post Smile
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  [HOWTO] Remote Wake, Reboot and Shutdown rickinoz 5 11,821 07-07-2016, 10:34 PM
Last Post: astromo
  [HOWTO] Remote Wake, Reboot and Shutdown 0 9,245 Less than 1 minute ago
Last Post:

Forum Jump:


Users browsing this thread: 1 Guest(s)