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

run-parts : failed to exec /etc/cron.daily/ntp exec format error

Despite being located in the /etc/cron.daily, any cron jobs located in this folder do not follow the crontab syntax.
Otherwise you will get this error :

run-parts : failed to exec /etc/cron.daily/ntp exec format error

Instead, make sure to set the programming language interpreter path used by your scripts using the shebang : #!

If it is a bash shell script, the first line of your job script must start with :

#!/bin/bash

or

#!/usr/bin/env bash

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

How to report when two files are the same ?

Comparing two files and looking for possible differences on a Linux like operating system is a common action.

diff is one of those utilities that you get to know when you deal with text files.

It is part of the coreutils, bundle of utilities provided by GNU : Coreutils manual

If you simply want to know if two files are the same, the GNU version of diff comes up with this feature using the -s or –report-identical-files options.

More information : Debian manpage for diff

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

[:ne binary operator expected

[:ne binary operator expected

In addition to the explanation here, this error pops up when comparing two values.
Pay attention either comparing is about comparing two strings or two numeric values.

As a reminder :

Numeric comparisons


val1 -eq val2
val1 -ne val2
val1 -ge val2
val1 -gt val2
val1 -le val2
val1 -lt val2

Strings comparisons


val1 = val2
val1 != val2
val1 val2
-n val1
-z val2

Further readings :

https://www.linuxtechi.com/compare-numbers-strings-files-in-bash-script/