Using sudo in script
I have a simple script that echos a line into my fstab file. It's probably not safe but I just using it for testing. Anyway, the second line works but for some reason the third always says permission denied even though I know it is running as root. Any ideas?
Code:
#!/bin/bash |
In your script only the echo is run with root privileges, but the current shell is the one that writes to the file. What you need to do is run a subshell with sudo:
Code:
sudo bash -c 'echo "//macx/swu /mnt/publicshare smbfs user,rw,noauto,username=swu" >> /etc/fstab' |
Yup, that was my problem, thanks.
|
All times are GMT -5. The time now is 08:28 PM. |