# Create A Systemd Timer

Systemd timers are a powerful alternative to `cron` for scheduling tasks, especially when you want better integration with system events like startup or specific conditions. Example of creating a simple systemd timer is given below -

## Example: Running a Command Automatically After System Boot

### 1. Create a systemd service file, for example: ***test\_timer.service***

```
[Unit]
Description=Example Systemd Service File.

[Service]
Type=oneshot
User=<username>
ExecStart=/usr/bin/ping -c 10 google.com

[Install]
WantedBy=multi-user.target
```

### 2. Now, create a timer file with the same name, for example: ***test\_timer.timer***

```
[Unit]
Description=Example Systemd Timer.

[Timer]
OnBootSec=5m

[Install]
WantedBy=timers.target
```

***Note:*** `OnBootSec=5m` ensures the service starts 5 minutes after the system boots up. Adjust the value based on your needs (e.g., `10s` for 10 seconds)

### 3. Enable & Start the Systemd Timer

```
sudo systemctl enable test_timer.timer
sudo systemctl start test_timer.timer
```

To check if the Systemd timer is enabled, we can use `systemctl list-timers` command to list out the various Systemd timer enabled on the system.

***Source(s):***

* [ArchWiki](https://wiki.archlinux.org/title/Systemd/Timers)
* [LinuxConfig](https://linuxconfig.org/how-to-schedule-tasks-with-systemd-timers-in-linux)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://til.devjugal.com/linux/systemd/create-a-systemd-timer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
