我正在运行以下代码来运行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
答案 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)