zoukankan      html  css  js  c++  java
  • php操作shee学习笔记之(一)PHP操作shell函数

    一、php操作shell

        1、system函数:执行普通命令

          string system (string $command [,int &$return_var])

          1)$command是命令字符串

          2)$return_var返回状态为0或非0

          3)函数最终返回字符串

          例:

            $shell="ls";    //ifconfig、free -m等

            system($shell,$s);

            echo $s;

        2、exec函数:返回数组结果

          string exec(string $command [,array &$output [,int &$return_var]])

          1)$command是命令字符串

          2)$output为返回数组

          3)$return_var为返回整形状态值为0或非0

          例:

            $shell="free -m";

            exec($shell,$arr,$s);

            var_dump($arr);

            echo $s; 

        3、需要root权限执行的命令 

          1)提升apache的进程守护者的sudo命令

            a、注释必须从tty终端执行sudo命令:visudo

              #Defaults  requiretty

            b、visudo命令设置sudo权限

              daemon ALL=NOPASSWD:/usr/sbin/useradd,/usr/sbin/init,/usr/sbin/userdel,/usr/bin/passwd

          2)php中执行该命令

            exec("sudo useradd user1",$status);

            echo $status;

            修改密码:$shell="echo 123 | sudo passwd --stdin user";

  • 相关阅读:
    mpvue: stylus定义主题色
    mpvue: 单个页面自定义导航栏或隐藏
    mpvue: fsevents is not a constructor
    Nginx:taro h5 Nginx代理配置
    git: 替换remote origin
    taro3.x: h5地图兼容组件封装
    taro3.x: h5地图兼容
    taro3.x: 使用taro-router在H5浏览器返回报错
    taro3.x: tarojs-router
    java线程与线程安全的单例模式
  • 原文地址:https://www.cnblogs.com/yuyangphpweibo/p/7906072.html
Copyright © 2011-2022 走看看