Setting up a desktop notification in Ubuntu after login

The following actions have been tested successfully on Ubuntu 19.04

Setting a desktop notification in Ubuntu after login requires creating a Desktop application following the Freedesktop specifications.
All such applications run as a user must be located in $HOME/.config/autostart

The autostart folder may not exist.
If not :

mkdir -p $HOME/.config/autostart

As an example, this desktop application will be named welcome.desktop

Create this file as follows :


touch $HOME/.config/autostart/welcome.desktop

Add the following lines in it :

cat welcome.desktop

[Desktop Entry]
Type=Application
Exec=/home/$USERNAME/Tools/
welcome_msg.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=myscript
Comment=Startup Script

Create the bash script welcome_msg.sh that will display the notification message :

cat welcome_msg.sh

#!/usr/bin/env bash

notify-send “Good morning ${USERNAME^} !” “Did you check your backups ?”

Make sure that the Exec field in your welcome.desktop file points to your script.

Reboot your Ubuntu machine and log in. Your custom desktop notification will be displayed !

Further readings :

https://cloudkul.com/blog/display-notification-login-ubuntu/

XDG autostart specification

Different ways of autostarting applications in Linux

Desktop Application Autostart Specification

Python auto-completion in Vim with python-jedi on Ubuntu 19.04

python-jedi is a plugin available for Vim that features auto-completion for the Python programming language.
It is available as an Ubuntu package :


apt install vim-python-jedi

To enable it as a user :


vim-addons install python-jedi

or


vam install python-jedi

To start using it in Vim, the keyboard shortcut CTRL+Space is a good start for auto-completing.

Further readings :

jedi autocompletion library for VIM

VIM for development on Stackabuse

Running anacron as a user

By default, anacron execute jobs as root.
Anacron jobs can be run as normal user as well.


mkdir -p .anacron/{etc,spool}

cp /etc/anacrontab .anacron/etc

The variables $HOME and $LOGIN are set to root by default in /etc/anacrontab. Adjust their values accordingly.

To make sure that your anacron jobs will be run, add the following line in your $HOME/.profile :


/usr/sbin/anacron -s -t $HOME/.anacron/etc/anacrontab -S $HOME/.anacron/spool

According to anacron’s manpage :

-s : serialize execution of jobs. Anacron will not start a new job before the previous one is finished.
-t : specify the anacrontab instead of using the default one.
-S : specify the spooldir to store timestamps in.

Sources :

Debian’s manpage for anacron

Debian’s manpage for anacrontab

Askubuntu answer

Anacron for specific user

Using shell variables in awk

It is possible to use shell variables within a awk command in a shell script.
As mentioned in the GNU Awk official documentation, one use case is that the shell variable holds the pattern that will be used by awk.
Here is one of the given examples :


printf "Enter search pattern: "
read pattern
awk -v pat="$pattern" '$0 ~ pat { nmatches++ }
END { print nmatches, "found" }' /path/to/data

If the pattern search is a bit more complicated than the one below $0 ~ pat, then this feature does not work anymore.

More details :

AWK : Using Shell Variables in Programs

Creating a systemd timer as a user on Debian 9.9

To set up a simple systemd timer as a user on Debian 9.9, here are the following steps to make it work.

Systemd version :

systemctl --version
systemd 232

As a user, both the .service unit and .timer unit must be located in $HOME/.config/systemd/user.
If this folder does not exist, create it :

mkdir -p $HOME/.config/systemd/user

If both the .service and .timer files are named as test, it must be enabled and started :


systemctl --user enable test

systemctl --user start test

The expected output should be found using journalctl :

journalctl -f

References :

https://wiki.archlinux.org/index.php/Systemd/Timers

systemd.time(7) manpage

Using systemd as a user

java.awt.headless

What is java.awt.headless ?

As well detailed in the article below,

Java contains a lot of classes which assume that there is a some sort of display and a keyboard attached. Sometimes, you are writing code to run on a server which does not have these and this is called Headless mode

For some Java-based web applications, graphics can be generated. Either you need to configure the application to use the local X Window server or use the Java Headless option.

Source : https://blog.idrsolutions.com/2013/08/what-is-headless-mode-in-java/

Use case example for headless image processing : https://github.com/processing/processing/wiki/Running-without-a-Display