Situation:
A non-root linux user owns a text file that's located in /etc/etc, where the non-root linux user does not have permission to create files. The non-root linux user can edit the file manually via vi without issue. Programmatic and manual attempts to replace a text string within the file using 'sed -i'sed -i, 'perl -i'perl -i, and other in-directory temp file methods are failing due to permissions issues when the non-root linux user runs the text-replacement script. I've found a solution in the Perl Cookbook (noted farther down) but it has concerning warnings, plus it looks a bit beyond me at present. Can anyone suggest a simpler option?
Server Info:
cat /etc/os-release --> Oracle Linux Server 8.9
uname -a --> Linux server01.domain.com 5.4.17-2136.322.6.4.el8uek.x86_64
perl - (v5.26.3) built for x86_64-linux-thread-multi
sed - (GNU sed) 4.5
awk - GNU Awk 4.2.1, API: 2.0 (GNU MPFR 3.1.6-p2, GNU MP 6.1.2)
vi - VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Aug 5 2022 07:42:15)
Location of file to edit:
/etc
Permissions on /etc:
drwxr-xr-x 130 root root 12288 Jun 21 11:50 etc
Text file to edit:
/etc/targetfile -rw-rw-r-- 1 justauser group1 1864 Jun 19 10:52 targetfile
File length of /etc/targetfile can be as large as 200 lines that are about 50 characters each.
cat /etc/os-release: Oracle Linux Server 8.9uname -a:Linux server01.domain.com 5.4.17-2136.322.6.4.el8uek.x86_64perl:
(v5.26.3) built for x86_64-linux-thread-multised:
(GNU sed) 4.5awk:
GNU Awk 4.2.1, API: 2.0 (GNU MPFR 3.1.6-p2, GNU MP 6.1.2)vi:
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Aug 5 2022 07:42:15)Location of file to edit:
/etcPermissions on
/etc:drwxr-xr-x 130 root root 12288 Jun 21 11:50 etcText file to edit:
/etc/targetfile-rw-rw-r-- 1 justauser group1 1864 Jun 19 10:52 targetfileFile length of
/etc/targetfilecan be as large as 200 lines that are about 50 characters each.
Example/abbreviated /etc/targetfile/etc/targetfile contents:
Constraints:
-Permissions on /etc can't change.
-Existing server programs/utilities can't be upgraded.
-All programs/commands must be called from within a bash shell script.
-The bash shell script must be executed as "justauser", not as root.
-Not using sudo is strongly preferred.
- Permissions on /etc can't change.
- Existing server programs/utilities can't be upgraded.
- All programs/commands must be called from within a bash shell script.
- The bash shell script must be executed as "justauser", not as root.
- Not using sudo is strongly preferred.
While logged in as the linux user "justauser", command line editing /etc/targetfile/etc/targetfile using vi works fine. Commands like 'sed -i'sed -i and 'perl -i'perl -i fail since "justauser" lacks write perms in /etc to create temp files.