-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput_cleanup
More file actions
50 lines (39 loc) · 1.27 KB
/
output_cleanup
File metadata and controls
50 lines (39 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
1. Create the service file (cleanup-output-dirs.service):
ini
[Unit]
Description=Delete output_* directories
After=multi-user.target
[Service]
Type=oneshot
User=username
WorkingDirectory=/home/username
ExecStart=/bin/bash -c 'find /home/username -maxdepth 1 -type d -name "output_*" -exec rm -rf {} \; 2>/dev/null'
StandardOutput=journal
StandardError=journal
2. Create the timer file (cleanup-output-dirs.timer):
ini
[Unit]
Description=Run cleanup-output-dirs daily at 1:00 AM
Requires=cleanup-output-dirs.service
[Timer]
OnCalendar=*-*-* 01:00:00
Persistent=true
[Install]
WantedBy=timers.target
3. Installation commands:
bash
# Copy files to systemd directory
sudo cp cleanup-output-dirs.service /etc/systemd/system/
sudo cp cleanup-output-dirs.timer /etc/systemd/system/
# Reload systemd and enable the timer
sudo systemctl daemon-reload
sudo systemctl enable cleanup-output-dirs.timer
sudo systemctl start cleanup-output-dirs.timer
# Check timer status
sudo systemctl status cleanup-output-dirs.timer
sudo systemctl list-timers cleanup-output-dirs.timer
Key differences from cron:
• OnCalendar=*-*-* 01:00:00 = Daily at 1:00 AM
• Persistent=true = Run missed jobs if system was down
• Better logging integration with systemd journal
• More robust service management and monitoring