Here is a simple method in which I am automating the creation of “Tomorrow’s notes” for my Obsidian.md notes[1]. In a similar manner, any simple tasks that needs to be repetitively done daily can be done with the help of bash scripting and cron job.
The above shows the daily notes I indent to create on a daily basis for the next day. This, I have implemented with the simple steps.
- Check if tomorrow’s file doesn’t exist (or if it exists, check if its empty)
[ ! -s filename ]
- If the above statement is true, create an empty file of the filename and copy the predefined texts to it.
You may have noticed that my Date Format is a bit different. This can be achieved using the linux’s date
command. This can be written as a bash script as follows:
|
|
The output of the cat command (which is the rest of the text until EOF) is piped to the file using a method called as Here document redirection. This can be extensively helpful in remote SSH sessions as well. Note that, you have to replace username
with your respective username. (One can also use the $HOME
variable if the service is initiated in user profile. I am not doing that). After creating, I had saved it with the filename create-daily.sh
.
The next step is to make it a daily task which gets automatically executed everyday. The problem with cron is that it is meant server environment. Hence, if your computer resumes after a shutdown, it won’t get executed. The solution is to use anacron which Ubuntu happens to use by default. Hence, one can simply copy the above script to a predefined folder as follows
|
|
If you are using WSL inside windows, you have to run the following to create the file compatibility with bash. (I haven’t actually run an anacron job inside WSL. Hence, if any issue rises, please let me know)
|
|
Thus, such simple but time consuming jobs can be automated.