Domiik
Domiik

Reputation: 233

How to shut down ubuntu using exec (php)

I would like to shut down ubuntu in php script.

I tried this exec("shuttown"); and exec("sudo shuttown");, but it didn't work.

Upvotes: 0

Views: 1167

Answers (3)

Greg Flynn
Greg Flynn

Reputation: 1744

exec("shutdown -h now");

It's a scary thought though that you would want a PHP script to have root privileges though

Upvotes: 1

Kaushik Shankar
Kaushik Shankar

Reputation: 5619

You are almost right; you have just misspelled shutdown, and have not given a time to shutdown.

As Tim Nordenfur said, simply calling shutdown now will execute that command.

For future reference, if you want to shutdown and restart it is exec("sudo shutdown -r now");.

Upvotes: 0

Tim
Tim

Reputation: 14164

The command is shutdown, and it requires a time given:

exec("shutdown now");

Also note that only root can run shutdown.

Upvotes: 2

Related Questions