bash 脚本位于 /opt/CleanUp.sh
find /home/*/Downloads/* -type f -exec shred -uz {} \;
rm -r /home/*/Downloads/*
find /home/*/Documents/* -type f -exec shred -uz {} \;
rm -r /home/*/Documents/*
find /home/*/Pictures/* -type f -exec shred -uz {} \;
rm -r /home/*/Pictures/*
find /home/*/Videos/* -type f -exec shred -uz {} \;
rm -r /home/*/Videos/*
find /home/*/Music/* -type f -exec shred -uz {} \;
rm -r /home/*/Music/*
exit 0
/etc/systemd/system/CleanUp.service 中的 .service 文件
[Unit]
Description=CleanUp Service
DefaultDependencies=no
Before=halt.target shutdown.target reboot.target
[Service]
Type=oneshot
ExecStart= /opt/CleanUp.sh
TimeoutStartSec=0
[Install]
WantedBy=halt.target shutdown.target reboot.target
脚本在关机时不执行。当我尝试通过以下方式启动它时
sudo service CleanUp start
我收到这个错误
× CleanUp.service - CleanUp Service
Loaded: loaded (/etc/systemd/system/CleanUp.service; enabled; preset: disabled)
Active: failed (Result: exit-code) since *****************; 7s ago
Process: 21217 ExecStart=/opt/CleanUp.sh (code=exited, status=203/EXEC)
Main PID: 21217 (code=exited, status=203/EXEC)
CPU: 1ms
*********** *hostname* systemd[1]: Starting CleanUp.service - CleanUp Service...
*********** *hostname* (eanUp.sh)[21217]: CleanUp.service: Failed to locate executable /opt/CleanUp.sh: Permission denied
*********** *hostname* (eanUp.sh)[21217]: CleanUp.service: Failed at step EXEC spawning /opt/CleanUp.sh: Permission denied
********** *hostname* systemd[1]: CleanUp.service: Main process exited, code=exited, status=203/EXEC
********** *hostname* systemd[1]: CleanUp.service: Failed with result 'exit-code'.
********** *hostname* systemd[1]: Failed to start CleanUp.service - CleanUp Service.
系统信息:Fedora Linux 37 (工作站版) x86_64 内核:6.2.9-200.fc37.x86_64 DE:GNOME 43.4