I am trying to write a script to edit systemd files.
On the CLI I can use the command:
sudo systemctl edit test.service
That opens a text editor, I make the changes and save no problems.
In a bash script I am trying to use the command:
sudo cat > /etc/systemd/system/test.service.d/override.conf <<EOF
[Service]
ExecStartPre=/sbin/iw dev wlan0 interface add ap0 type __ap
EOF
It doesn't work because I don't have the right permissions.
I can then run the command:
sudo touch /etc/systemd/system/test.service.d/override.conf
and that works.
If I then run again:
sudo cat > /etc/systemd/system/test.service.d/override.conf <<EOF
[Service]
ExecStartPre=/sbin/iw dev wlan0 interface add ap0 type __ap
EOF
It also fails on permissions.
As far as I can see, this seems to be an issue with the:
sudo cat > somefile << EOF
some file text
EOF
command sequence. sudo should break through any permission issues, but doesn't in this case.
Is there a solution??