mv命令无法使用bash脚本php

时间:2016-04-26 14:48:57

标签: php linux bash

我正在运行以下代码来运行bash命令

shell_exec("sudo sh script.sh $conf_file");

$config_file包含例如abc.conf

的值

在我的script.sh文件中

#!/bin/bash
mv $1 /etc/apache2/sites-available/

我还允许www-data用户使用sudo而不使用密码,转到sudo visudo并在最后添加以下行

www-data ALL=NOPASSWD: /var/www/html/myapp/script.sh

1 个答案:

答案 0 :(得分:2)

您正在使用sudo运行sh,而不是/var/www/html/myapp/script.sh。当您的脚本以行script.sh开头时,为sh #!/bin/bash运行shell_exec的原因也很奇怪。只需尝试将shell_exec("sudo /var/www/html/myapp/script.sh $conf_file"); 更改为:

class Parent(db.Model):
    __tablename__ = ‘parent220416'
    id = db.Column(db.Integer, primary_key=True)
    children = db.relationship(‘Child’, backref=‘Parent’, lazy='dynamic')

class Child(db.Model):
    __tablename__ = ‘child220416'
    id = db.Column(db.Integer, primary_key=True)
    parentid = db.Column(db.Integer, db.ForeignKey('words220416.id'))
    data = db.Column(JSONB)