Solved

shutdown linux with vbs code

Posted on 2008-10-10
11
754 Views
Last Modified: 2013-12-06
code to make vbs file to shutdown linux system.
0
Comment
Question by:ankur3020
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
11 Comments
 
LVL 3

Expert Comment

by:fcarrai
ID: 22693196
You can open a network socket over the TELNET port, login and send the shutdown command.
Shouldn't be hard to code...
P.S. Standard telnet session are not encrypted. Depending where is the system to shutdown, that could be an issue.
0
 

Author Comment

by:ankur3020
ID: 22694625
can do all this by running vbs or some other file
0
 
LVL 1

Expert Comment

by:WANM
ID: 22787116
If you have enough access to the linux box, and it's running a web server, I would do this by creating a CGI script to do the shutdown (by running "poweroff" on the linux box) and protect it with a password. Then access the CGI script by accessing http://whatever from vbscript. This would be more secure than opening a telnet session, and you could even use https:// if so desired. It also limits the potential for damage if the password were obtained by someone inappropriate.

My next choice would be to have the vbscript run something like putty's command line tool:
"plink -pw password user@host command"

plink will also handle telnet as well as ssh sessions, but ssh is much preferred.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ankur3020
ID: 22787722
then pls give me complete code
0
 
LVL 1

Expert Comment

by:WANM
ID: 22787817
for which option? is installing free 3rd party software on the windows box an available option (required for the putty approach, but much quicker to code)

which methods are available for connecting to the linux box (does it have a web server, ssh, or telnet server?)

Will the connection be made only over your local LAN or does it need to be secure enough for access across the internet?
0
 

Author Comment

by:ankur3020
ID: 22788270
with cgi script as i have direct access to linux and it is running a web server.
0
 
LVL 1

Accepted Solution

by:
WANM earned 125 total points
ID: 22792997
On the linux end, create a directory in the htdocs folder (type "locate htdocs" if you don't know where that is) called "cmd" (anything you like really, just make sure you make the change to the scripts below)

In the cmd directory, place the following files:
cmd.cgi
------------------
#!/bin/bash

echo ""

if [ "$QUERY_STRING" == "shutdown" ]; then
   echo "Shutting Down the system"
   sudo /sbin/poweroff
else
   echo "Unknown Command"
fi
--------------------
.htaccess
--------------------
Options +ExecCGI
order deny,allow
deny from all
satisfy any
AuthName "Commands"
AuthType Basic
require valid-user
AuthUserFile htdocs/cmd/.htusers
-------------------

Make cmd.cgi executable:
chmod +x cmd.cgi

and run this command to set the username and password: (replace <username> with something appropriate)
htpasswd -cm .htusers <username>


Now add the following two lines to /etc/sudoers to allow the nobody user to run /sbin/poweroff (the web server will probably be running as user nobody - if it's running as a different user, change the "nobody" to that user)

Cmnd_Alias POWEROFF=/sbin/poweroff
nobody ALL=(root) NOPASSWD: POWEROFF

That takes care of the linux end of things

For the vbscript:

shutdown_server.vbs
------------------------
Dim xmlhttp
Set xmlhttp=CreateObject("Microsoft.XMLHTTP")
xmlhttp.Open "GET", "http://server.address/cmd/cmd.cgi?test", false, "<username>", "<password>"
xmlhttp.Send
WScript.Echo xmlhttp.responseText
--------------------------

Replace server.address, <username> and <password> with the appropriate values of course.

For testing you might want to replace /sbin/poweroff with something more benign - like:
/bin/ls /root
0
 
LVL 1

Expert Comment

by:WANM
ID: 22793011
0
 

Author Comment

by:ankur3020
ID: 22837783
the coed u gave is ok and in case i have any trouble i will tell u later. thanks
0
 

Author Closing Comment

by:ankur3020
ID: 31505257
thanks
0
 
LVL 1

Expert Comment

by:WANM
ID: 22841520
one thing I forgot to mention - configuring sudo to allow the web server user to run poweroff presents an opportunity for any user who can create cgi scripts on the web server to shut the system down - if this is a problem, you will want to look into apache's suexec support which allows you to execute a script as a particular user (whoever the owner of the script is) - it is more difficult as suexec support is not enabled by default in apache last time I looked.
You don't want to run the script as root, but as another user (possibly your own account) and give only that user access to run poweroff.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question