Sample Header Ad - 728x90

dhclient exit hook cannot write to directory

0 votes
0 answers
91 views
I am using RHEL 8.9 and have created a basic dhclient hook script in which I want to log to a file. The script is able to write to places like /tmp, but not /opt. It can *read* files from /opt, but not write to the directory:
-shellsession
[root@server]# ls -la /etc/dhcp/dhclient-exit-hooks.d/test.sh
-rwxr-xr-x. 1 root root 159 Feb 12 22:47 /etc/dhcp/dhclient-exit-hooks.d/test.sh

[root@server]# cat /etc/dhcp/dhclient-exit-hooks.d/test.sh
#!/bin/bash
{ date; cat /opt/test1.txt; } >> /tmp/test1.txt # works as expected (reading from /opt and writing to /tmp)
date >> /opt/test2.txt # does not work; cannot write to /opt
When testing the hook I am seeing permission issues:
-shellsession
[root@server]# dhclient eth0
/etc/dhcp/dhclient-exit-hooks.d/test.sh: line 3: /opt/test2.txt: Permission denied
I have verified that write access is granted on the file in /opt, and even gone so far as to give write/execute to all users on the directory:
-shellsession
[root@server]# ls -la /opt/
total 8
drwxrwxrwx.  2 root root  40 Feb 12 22:46 .
dr-xr-xr-x. 17 root root 224 Dec 21 10:37 ..
-rw-rw-rw-.  1 root root   4 Feb 12 22:45 test1.txt
-rw-rw-rw-.  1 root root   4 Feb 12 22:46 test2.txt
File reading/writing to /tmp is working without issues. I also can run the script directly with root and not face any permission issues (it works as expected). Any ideas?
Asked by trebor (111 rep)
Feb 12, 2024, 10:51 PM
Last activity: Feb 22, 2024, 12:59 PM