My startup application isn't running on Ubuntu 22.04

On my personal computer, I’m having no success getting a custom application to run upon login on Ubuntu 22.04, so I’ve added some toy examples to ‘Additional startup programs’, and none of them seems to be in

date > startup.date
date > /home/me/startup.date
date > /tmp/startup.date

I expect to find a file ~/startup.date after logging in as myself, but it is absent. What’s the trick to getting these to work?

(I don’t want something to run on every login, as .bashrc or .profile might do.)

enter image description here
enter image description here

Asked By: Jellicle

||

The question is about a "custom application" failing to work with Startup Application. It is not clear if this "custom application" is a shell script or not. A properly written shell script beginning with a shebang should work without the bash -c prefix. However, for a shell command like date, the example in the question, the bash prefix is needed. The rest of the answer is about the specific example in the question.

Login log (make Your Own)

The intent is to record and find out when the user logged in. The commands below are to be entered in the Startup Applications as indicated in the question. The correct syntax is:

bash -c 'date > startup.date'

Note, the above command will create or overwrite the file startup.date every time the user logs in. It does not record the date and time the computer was started up.

One issue with this command is that it overwrites the file. So only one record is retained. If the intent is to keep a log of every login, then the next command works better:

bash -c 'date >> login.log'

Note the double greater than sign >>. This appends the date to the existing file.

Login log (system generated)

There is no need to create entries in the Startup Application as the system already records login events. This section describes how to access these logs easily from the terminal.

Ubuntu provides a handy command to review system generated login and reboot logs. By default, the last command uses the system log file /var/log/wtmp as the data source to generate reports. wtmp is a binary file on Unix-based operating systems. It keeps a record of all reboot, login and logout activity.

It can display various information, including the date and time of access, the duration of the session, and the device or terminal used to access the system. Running the last command without passing any options or specifying a username (or the keyword reboot) prints all users that have previously logged in as well as when the computer was rebooted.

$ last
redward  :0           :0               Tue Apr 18 09:48   still logged in
reboot   system boot  5.15.0-67-generi Tue Apr 18 09:47   still running
redward  :0           :0               Thu Apr 13 10:51 - crash (4+22:56)
reboot   system boot  5.15.0-67-generi Thu Apr 13 10:47   still running
redward  :0           :0               Mon Apr 10 21:59 - crash (2+12:48)
reboot   system boot  5.15.0-67-generi Mon Apr 10 21:58   still running
redward  :0           :0               Wed Apr  5 22:33 - down  (4+23:24)
.... truncated ....

redward is the username who had logged in, in this example.

The first column shows the username of the logged-in user, and the second column shows how the user is accessing the system, for example, via teletype (TTY) or pseudo-terminal. However, it shows “system boot” if it’s a restart task.

The third column shows us where the user logged in from. We should expect to see a hostname or an IP address if the login was from a remote computer, an empty value if it was via teletype, or the kernel version if it’s a reboot task.

Finally, the fourth column shows when the login activity happened, and the fifth column shows the logout time. The last column shows how long the user has been connected in the format “Hours: Minutes“.

If you want to know the login times of the current logged in user (you), open a terminal by pressing Ctrl+Alt+T and enter:

last $USER | head -5

The | head -5 part shows the last 5 logins by the current user. You may specify multiple users to find out about last logins by other users of the computer:

last barbie ken | head -5

See man last for various options

Reference: https://www.baeldung.com/linux/monitor-login-attempts

Hope this helps

Answered By: user68186
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.