views:

24

answers:

2

I'm currently writing a script to automate our CMS setup and deployment. Part of that process is adding an alias to Apache2 which is normally done manually via Webmin. At current, I'm looking to append a line into the Apache2 include file that stores all the alias, using the following:

echo Alias /path \"/var/www/directory\" >> alias.include

The problem I have is that this include file is owned by root and currently has the permissions -rw-r-r-. The only way i can append this file is to chmod the permissions, make the change, then chmod it back. This seems really dodgy to me. Any suggestions?

A: 

What about changing the owner of the include files to the one that does the update?

cd /alias/path
chown user *.include

The file is of course still readable/writable by root.

Or a ligther version, create a new group to which only user belongs.

groupadd newgroup
usermod -a -G newgroup user
cd /alias/path
chgrp newgroup *.include
chmod 664 *.include
ring0
A: 

Unless you use a filesystem that supports ACLs, your options are to

  • run the bash script as root.
  • change the ownership or group of the file to match the user running the script.
shreddd