I am writing a script and I need to be able to write additional configuration information to a .conf
file.
The Issue:
The issue is I am unable to write additional data to a file due to a permission issue. Here is the code I am using:
my $conf = "/etc/lighttpd/lighttpd.conf";
open my $handle, ">>", $conf or die $!;
# spacing counts, hence the indentation
print $handle 'fastcgi.server = (
".php" => ((
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/tmp/php.socket"
))
)'."\n";
close $handle;
Since the lighttpd.conf
file is under the umbrella of root:root
, I'm unable to write it without doing something along the lines of:
system("sudo chown $USER:$USER /etc/lighttpd/lighttpd.conf");
# write to file...
system("sudo chown root:root /etc/lighttpd/lighttpd.conf");
The above seems rather hackish to me and I'd rather avoid this.
The Question
Are there more elegant ways to go about writing this information to the file? Perhaps a BASH command I am unaware of?