M. Barbieri M. Barbieri - 4 months ago 6
Linux Question

Trying to make a bash script that restarts all services within a certain directory

I have made this simple little script to try and restart all services within a directory:

systemctl daemon-reload
for service in /etc/systemd/system/multi-user.target.wants/*
systemctl restart $service

When I try to run this I get the following error:

Failed to restart etc-systemd-system-multi\x2duser.target.wants-openvswitch.service.mount: Unit etc-systemd-system-multi\x2duser.target.wants-openvswitch.service.mount failed to load: No such file or directory


You need to extract the basename from the $servicevariable

systemctl restart $(basename $service)