I'm using the Config::Hosts to make updates to the /etc/hosts file. My script runs under my regular user account and so it is unable to write to the /etc/hosts which is owned by root. I tried slapping sudo in front of it but then started getting errors (root doesn't know where my personal perl library resides). Plus, I prefer my script to run as a regular user so the files it writes are owned by my regular user.
One approach I'm considering is to give the user my script runs under NOPASSWD access to the chmod command and then having my script sudo chmod on the /etc/hosts file temporarily and then switch back to the original permissions. This seems like a less than ideal, solution. I'm wondering if there might be a better idea.
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks
In reply to Best way to write to a file owned by root? by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |