Schedule a Daily Job

Linux lab Intermediate 3 tasks 20 points

A script at /usr/local/bin/cleanup.sh clears out old files. Schedule it to run every day: write a service and a daily timer, then enable the timer so it's active now and at boot. Password: student.

How it works: the terminal below is a real Linux machine running in your browser. Click it and type. Tasks tick themselves off as you complete them; questions are answered in the box under each task. Press Reset any time for a fresh machine. Your password on this machine (for sudo) is student.

student@vulntech:~ Starting…
Getting your Linux machine ready…
The first start downloads about 20 MB. After that your browser keeps it, and labs start in a moment.

Hints

Write each unit with sudo tee /etc/systemd/system/NAME <<'EOF' ... EOF.

enable --now on the .timer does both “now” and “at boot”.

Solution explanation

The oneshot cleanup.service holds the work (running the script); cleanup.timer holds the schedule (OnCalendar=daily) and installs into timers.target. After daemon-reload, enable --now cleanup.timer makes the timer active immediately and at every boot — you enable the timer, not the service.

Show solution
sudo tee /etc/systemd/system/cleanup.service > /dev/null <<'EOF'
[Unit]
Description=Clean up old files

[Service]
Type=oneshot
ExecStart=/usr/local/bin/cleanup.sh
EOF
sudo tee /etc/systemd/system/cleanup.timer > /dev/null <<'EOF'
[Unit]
Description=Daily cleanup

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now cleanup.timer
systemctl list-timers cleanup.timer --no-pager
HOME LEARN COMMUNITY DASHBOARD