php - Run shell command and send output to file? -
i need able modify openvpn auth file via php script. have made http user no-pass sudoer, machine available within home network.
i have following commands:
echo shell_exec("sudo echo '".$username."' > /etc/openvpn/auth.txt"); echo shell_exec("sudo echo '".$password."' >> /etc/openvpn/auth.txt");
but when run, not change file @ all, or provide output in php.
how make work?
when run
sudo command > file
only command run sudo, not redirection.
as pointed out, sudo sh -c "command > file"
work. unless, want run command
sudo, should not it. can run redirection part sudo. answer rici covers 2 methods it. here method:
command | sudo tee filename >/dev/null #to overwrite (command > file) command | sudo tee -a filename >/dev/null # append (command >> file)
Comments
Post a Comment