• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 818
  • Last Modified:

shutdown linux with vbs code

code to make vbs file to shutdown linux system.
  • 5
  • 5
1 Solution
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.
ankur3020Author Commented:
can do all this by running vbs or some other file
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.

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

ankur3020Author Commented:
then pls give me complete code
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?
ankur3020Author Commented:
with cgi script as i have direct access to linux and it is running a web server.
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:

echo ""

if [ "$QUERY_STRING" == "shutdown" ]; then
   echo "Shutting Down the system"
   sudo /sbin/poweroff
   echo "Unknown Command"
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

That takes care of the linux end of things

For the vbscript:

Dim xmlhttp
Set xmlhttp=CreateObject("Microsoft.XMLHTTP")
xmlhttp.Open "GET", "http://server.address/cmd/cmd.cgi?test", false, "<username>", "<password>"
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
ankur3020Author Commented:
the coed u gave is ok and in case i have any trouble i will tell u later. thanks
ankur3020Author Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now