LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-31-2006, 07:31 AM   #1
spank
Member
 
Registered: Aug 2003
Location: Romania
Distribution: Ubuntu 6.06
Posts: 278

Rep: Reputation: 30
php halt script


I want to do a php script that halts the pc.
how can i do that?
i've tried:
Code:
<?
exec('halt');
?>
but it doesn't happen anything.
how can i solve it?

thank you!
 
Old 07-31-2006, 07:46 AM   #2
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
Maybe there's a good reason not to call this function from PHP. The permissions for halt on many machines might rest only with the super user. PHP usually doesn't (and shouldn't) run as super user on the server.
 
Old 07-31-2006, 07:51 AM   #3
spank
Member
 
Registered: Aug 2003
Location: Romania
Distribution: Ubuntu 6.06
Posts: 278

Original Poster
Rep: Reputation: 30
yes i'm aware of the risk that doing this think implies but i still want to do it. any ideeas on how to do it ?
 
Old 07-31-2006, 07:54 AM   #4
musicman_ace
Senior Member
 
Registered: May 2001
Location: Indiana
Distribution: Gentoo, Debian, RHEL, Slack
Posts: 1,555

Rep: Reputation: 46
Shouldn't it be
<?
system('halt')
?>


Also, whomever the apache server is running as, give that user sudo priveledge for halt and then try your code running sudo halt. I'm not sure if it'll work, but its a thought.

Last edited by musicman_ace; 07-31-2006 at 07:56 AM.
 
Old 07-31-2006, 07:56 AM   #5
spank
Member
 
Registered: Aug 2003
Location: Romania
Distribution: Ubuntu 6.06
Posts: 278

Original Poster
Rep: Reputation: 30
it's the same thing
 
Old 07-31-2006, 08:10 AM   #6
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
Without knowing your system configuration we're only going to guess why it doesn't work. You haven't even given any error messages (if any) or how PHP is set up in your system. We don't even know whether you're calling this from the command line... I'm assuming you are.
 
Old 07-31-2006, 11:36 AM   #7
spank
Member
 
Registered: Aug 2003
Location: Romania
Distribution: Ubuntu 6.06
Posts: 278

Original Poster
Rep: Reputation: 30
ok.... sorry about that.

I have Apache/2.0.55 and PHP/5.1.2 on an Ubuntu Server 6.06. I just want to create a php script with which i want to shutdown the server via my browser.
i've created test.php
Code:
<?
        echo "<hr>";
        echo system('halt');
        echo "<br><hr>";
?>
between the lines i don't get any error message.

NOTE: as a desperate method i've chmoded /sbin/halt to 777 and it still doesn't work.
 
Old 07-31-2006, 04:27 PM   #8
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Do you have safe mode enabled? Also, what do your Apache error logs say?
 
Old 08-02-2006, 12:56 PM   #9
spank
Member
 
Registered: Aug 2003
Location: Romania
Distribution: Ubuntu 6.06
Posts: 278

Original Poster
Rep: Reputation: 30
in error.log i have:
Code:
halt: must be superuser.
how can i make user www-data be able to halt the computer ?
 
Old 08-02-2006, 02:39 PM   #10
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Like musicman_ace already said you better check out sudo.
 
Old 08-02-2006, 02:59 PM   #11
Mcribs
LQ Newbie
 
Registered: Nov 2005
Location: Chicago
Distribution: Debian
Posts: 15

Rep: Reputation: 0
I thought system commands were called in the scipt through the usage of "print `command`;"?
 
Old 08-02-2006, 03:06 PM   #12
spank
Member
 
Registered: Aug 2003
Location: Romania
Distribution: Ubuntu 6.06
Posts: 278

Original Poster
Rep: Reputation: 30
how can i do the sudo thing?

i do a visudo and add the lines:
Code:
Cmnd_Alias      HALT = /sbin/halt
www-data        ALL= HALT
and modify the script to:
Code:
<?
        echo "<hr>";
        echo system('sudo /sbin/halt');
        echo "<br><hr>";
?>
but if i check the error.log it says:
Code:
Passwd:
i guess it prompts me for a passwd. shouldn't sudo halt work without asking for the pass? how can i enter the pass?
 
Old 08-02-2006, 07:45 PM   #13
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Sudo by default requires a password (for the obvious security reasons). If you're absolutely positive that you want to do this, check out the documentation: http://www.courtesan.com/sudo/man/su...swd_and_passwd.
 
Old 08-03-2006, 02:58 AM   #14
spank
Member
 
Registered: Aug 2003
Location: Romania
Distribution: Ubuntu 6.06
Posts: 278

Original Poster
Rep: Reputation: 30
thank you... solved that. I added the line to /etc/sudoers:
Code:
www-data        ALL= NOPASSWD: /sbin/halt
and then all went smothly.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Title: PHP/MySQL Classifieds Script AddAsset1.php Script Insertion LXer Syndicated Linux News 0 07-02-2006 06:21 PM
issues with mirc script accessing our php script dtra Linux - Software 2 07-02-2005 04:30 PM
script execution on halt linuxhippy Slackware 4 04-01-2005 07:09 PM
PHP -- How to execute a shell script from PHP using FTP functions?? zoonalex Programming 3 07-29-2004 11:51 AM
converting shell script to php script ? ibro Linux - General 6 05-24-2004 05:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration