> For the complete documentation index, see [llms.txt](https://my-learning-journey.devjugal.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://my-learning-journey.devjugal.com/content/2024/december/day-13.md).

# December 13, 2024

## Things That I Discovered

### 1. Prevent cronjobs from overlapping

* I recently started running Systemd timer for a recurring task; rclone sync, and wanted bare minimum time to re-run it, but here comes a caveat, if the execution doesn't finish in time, a new task might be started, resulting in overlap, and if the task is handling data, say database for an example. That can lead to data loss/corruption. We can use `flock` command to overcome this.
* **Example:**

  ```
  flock /var/lock/rclone-sync.lock -w 30 rclone sync <SOURCE> <DESTINATION>
  ```
* Here, `flock` command would check for a lock file at `/var/lock/rclone-sync.lock` and wait for 30 seconds before it exits with an error if a lock file is found.
* Read more at my TIL [Website](https://til.devjugal.com/linux/systemd/prevent-systemd-timers-from-overlapping).
* **Reference(s):**
  * [CleverUptime](https://cleveruptime.com/docs/commands/flock)
  * [Mattias Geniar Blog](https://ma.ttias.be/prevent-cronjobs-from-overlapping-in-linux/)
  * [Bashscript.net](https://bashscript.net/using-flock-in-bash-scripts-manage-file-locks-and-prevent-task-overlaps/)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://my-learning-journey.devjugal.com/content/2024/december/day-13.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
