Koozali.org: home of the SME Server

Legacy Forums => General Discussion (Legacy) => Topic started by: Gert on March 03, 2002, 05:12:25 PM

Title: Quick shutdown
Post by: Gert on March 03, 2002, 05:12:25 PM
Is it posible to shut down e-smith from my windows client
whitout using the server-manage.
 
i am planning to use a script to shutdown both windows and e-smith
Title: Re: Quick shutdown
Post by: Dan G. on March 03, 2002, 06:09:44 PM
....and now for something completely different...

You _may_ be able to accomplish what you are trying to do with an HTTP bot.  Have a look at http://www.davecentral.com/projects/internetrobot/, and other projects at davecentral.com.  You would need to figure out what strings to send to the e-smith-manager, but it might just work :)

Dan
Title: Re: Quick shutdown
Post by: Michael on March 03, 2002, 11:38:04 PM
Before you're going to pay for such a program get the "Perl Cookbook" instead, download ActivePerl for free and copy some Perl script out of the book to do the job.
Title: Re: Quick shutdown
Post by: Les Mikesell on March 05, 2002, 12:12:21 AM
A command line ssh client is a good way to script things remotely.  The 'plink' tool that comes with the free putty.exe should work, or if you want something more unix-like you can install the tools from www.cygnus.com.   Running '/sbin/shutdown -h now'  on the server should stop it.
Title: Re: Quick shutdown
Post by: Gert on March 05, 2002, 12:29:41 PM
Do you know what script to copy ?
Title: Re: Quick shutdown
Post by: Michael on March 05, 2002, 12:36:38 PM
Assuming you're talking to me :-). Have a look at "20.2. Automating Form Submission" in the "Web Automation" chapter.
Title: Re: Quick shutdown
Post by: Gert on March 05, 2002, 01:46:12 PM
www.cygnus.com get me to www.redhat.com
can't find anything there.

I downloaded putty.exe and plink but how exacly can i shut down e-smith whit it ?
Title: Re: Quick shutdown
Post by: Gert on March 05, 2002, 02:34:08 PM
Got it :-)

Somthing like.
****************************************************
use LWP::Simple;
use URI::URL;

my $url = url('http://www.perl.com/cgi-bin/cpan_mod');
$url->query_form(module => 'DB_File', readme => 1);
$content = get($url);
If you're using the POST method, create your own user agent and encode the content appropriately:

use HTTP::Request::Common qw(POST);
use LWP::UserAgent;

$ua = LWP::UserAgent->new();
my $req = POST 'http://www.perl.com/cgi-bin/cpan_mod',
               [ module => 'DB_File', readme => 1 ];
$content = $ua->request($req)->as_string;
*****************************************************
How do i get further ?
My shutdown site is at: Http://Linux-server/server-manager/cgi-bin/reboot

please help me, i am very new in script and programming.
Title: Re: Quick shutdown
Post by: Michael on March 05, 2002, 02:49:42 PM
Gert

I do not try this myself, as I don't want to shut my box down right now. But have a try with the following lines:

my $url = url('http://myE-SmithBox.mydomain.net/server-manager/cgi-bin/reboot');
$url->query_form(function => 'shutdown', action => 'Perform', state => 'perform');
$content = get($url);
Title: Re: Quick shutdown
Post by: Gert on March 05, 2002, 10:23:36 PM
Well, it's allmost there.(i hope)
i made a perl script like this:
***************************************
use LWP::Simple;
use URI::URL;

my $url = url(http://Linux-server/server-manager/cgi-bin/reboot);
$url->query_form(module => shutdown, action => Perform, state =>perform);

$content = get($url);
***************************************
It is opening and closing a black box very quickly.
It is connecting the right ip adresse but nothing seams to happend.
i don't get any errors.

im lost, please help

gc
Title: Re: Quick shutdown
Post by: Les Mikesell on March 06, 2002, 09:30:39 AM
> www.cygnus.com get me to www.redhat.com
> can't find anything there.

Oops, the site is http://www.cygwin.com these days.  Those tools may be overkill if you don't want most of the unix environment on your windows box.

> I downloaded putty.exe and plink but how exacly can i shut
> down e-smith whit it ?

First try it interactively to make sure the ssh service is enabled on the server. Use putty to connect to the server using ssh.  Log in as root - if you want to shut down at that point the command 'reboot -h' should work, or 'shutdown -h now'.   Then in a script you can use plink to send the same command.
Title: Re: Quick shutdown
Post by: Gert on March 06, 2002, 01:01:39 PM
Att: Les

OK, i got Putty to connect to my server, but it wont accept my root password.

What can be wrong ?

gc
Title: Re: Quick shutdown
Post by: Paul Lakra on March 06, 2002, 01:56:59 PM
Make sure you use 'admin' as the user name. This one caught me out.
Title: Re: Quick shutdown
Post by: Norrie on March 06, 2002, 02:16:28 PM
Hi folks,

I tried the plink method yesterday.  I got as far as getting plink to automatically log into the server as root but I still have to supply the (root) password.  Paul, why admin as the username?  I've never had trouble logging into e-smith as root with putty.

Anyway.  I got stuck when trying to add the public key info to e-smith to enable non-interactive log ins with putty / plink.  (See the putty site)

Anyone help?

NTB
8o)
Title: Re: Quick shutdown
Post by: Paul Lakra on March 06, 2002, 03:02:59 PM
Sorry - I jumped in a bit too quickly here without reading what went before. I have not played with my e-smith box for a few weeks but I remember there was some problem logging in as root. I have not got my notes with me here. If this thread is still running later I'll check when I get home.
Title: Re: Quick shutdown
Post by: Les Mikesell on March 07, 2002, 05:53:44 AM
In the server-manager setup for remote access, be sure you have selected 'yes' for command line access and standard passwords.   If you log in as admin you will get the SME console menu.  If you log in as root you will get a # prompt and the usual god-like power over the machine.  Setting up passwordless access takes a little more work.  You have to create a public/private key pair, keeping the private key in the usual place for your ssh client and adding  a copy of the public key to the /root/.ssh/authorized_keys file.  I do most of my remote work from a Mandrake 8.1 box that has a nifty 'ssh-copy-id' script that uses a password-based session to automatically do the grunge work of copying the key to the right place for you.
Title: Re: Quick shutdown
Post by: Norrie on March 07, 2002, 12:37:07 PM
You have to create a public/private key pair, keeping the private key in the usual place for your ssh client and adding a copy of the public key to the /root/.ssh/authorized_keys file.

This is the point I'm stuck at.  The authorized_keys file didn't exist so I created it with pico and pasted the key (by right clicking in putty) but I'm not sure if there should be any spaces or carriage returns.  When I try to log into the server automatically using the saved putty config I get

Using username "root".
Server refused our key
root@192.168.0.254's password:

What should the authorized_keys file look like?  Anyone got any other ideas?

Thanks

Norrie
8o)