Login script that runs only once per user (Linux)
While preparing a Linux server for general use, you might want to initialize certain aspects of the environment at the first login by the user. This article assumes that your shell is
bash starts, it executes commands from different scripts in the order given below.
1.1 Loads all
To check which shell you have, type
You may modify the files, but it is usually a good idea to have your own
custom.sh file created inside
/etc/profile.d if you want a certain script to be executed for all users.
You can use this simple script structure to execute something for the first time a user logs in.
#!/bin/bash if [ -e $HOME/.yourflag ] then echo "No steps required" else echo "Your steps go here" touch $HOME/.yourflag fi
It is a fairly simple structure as you can see and it checks if a particular flag exists.
I hope this helps!
Well, stay tuned for upcoming articles. You may contact us at firstname.lastname@example.org for your software and consultancy requirements.