Run shell command and send output to file?

前端 未结 2 974
北荒
北荒 2021-01-27 23:37

I need to be able to modify my openvpn auth file via a php script. I have made my http user a no-pass sudoer, as this machine is only available within my home network.

2条回答
  •  难免孤独
    2021-01-28 00:08

    Instead of running an entire shell process as root, which is arguably unsafe, you can run the copy as root:

    (with bash):

    sudo cp <(echo "$username") /etc/openvpn/auth.txt
    

    (should work with any shell):

    echo "$username" | sudo dd of=/etc/openvpn/auth.txt
    

提交回复
热议问题