How to keep date and time up to date after resuming from sleep mode

If you’re running Ubuntu Linux within a VM, time and date may not be accurate after resuming from sleep mode.

timedatectl provides a way to display and modify date and time information.

To get full details about the current date/time/time zones settings :

timedatectl status

Syncing date and time information with a ntp server is relevant.

timedatectl set-ntp true

To see the modification in effect :

timedatectl status

The NTP service information should be updated from inactive to active.

Advertisements

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

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