PHP执行shell
跳到导航
跳到搜索
PHP - 执行shell
php
<?php exec("/var/www/html/killpidginf.sh"); ?>
SHELL
#!/bin/sh ssh [email protected] "netstat -lntp |grep ':32022' |grep 'tcp '|awk '{print \$7}'|awk -F'/' '{print \$1}'|xargs kill -9" echo 0
权限
执行远程机器上的 shell,需要: * 在 /var/www/.ssh 放入 id_rsa 及 known_hosts,所有者设置为当前 web 执行者,如:www-data:www-data
Example
- index.html
<html> <head> <meta charset="utf-8" /> </head> <p style="font-size:80px"> Menu:</p> <p style="font-size:24px"> 没事别乱按下面链接,除非特别需要。</p> <p style="font-size:80px"> <span> 1. <a href="killpidginf.php">restart M202 tunnel</a></span> </p> </html>
- killpidginf.php
<!DOCTYPE html>
<html>
<body>
<?php
exec("/var/www/html/mwbbs/killpidginf.sh");
echo " <p style='font-size:80px'> Result:</p>";
echo "<p style=\"font-size:40px\">";
echo " Success! Wait a minute and try connecting again.";
echo "</p>";
?>
</body>
</html>
- killpidginf.sh
#!/bin/sh ssh [email protected] "netstat -lntp |grep ':32022' |grep 'tcp '|awk '{print \$7}'|awk -F'/' '{print \$1}'|xargs kill -9" echo `date "+%Y-%m-%d %H:%M:%S"` restart g-inf ssh tunnel. >> log_mwbbs.log echo 0