[SOLVED] How do I make a script run once upon first time login?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How do I make a script run once upon first time login?
Hi, I am just wondering how I would go about making a script run the first time a user logs in? It's specifically so I can make a mysql account for all new users, and preferably I'd like the script to delete itself upon successful execution.
You could, perhaps, provide a general-purpose script to add the account, and add a line to run this from the .profile script in the user's home directory, for example:
Code:
/usr/bin/add_mysql_user.sh $USER
Then add a line to the end of the "add_mysql_user.sh" script, to delete this line once it has been run:
Ok, that sounds like a good idea, I was just reading up on the .bash_profile file, is that the same one? Or should I go with .profile if it's a seperate file...However how do I get $USER into that file?
At a guess, is it similar to how a function works, in that the mysql_add_user.sh is written with the $USER variable in place,....and it just takes the actual user name and does its job?
Hmm... in Debian I don't have a .bash_profile script, but I think putting it there will achieve the same thing. You just need a script that is executed at login.
Quote:
Originally Posted by Karas
At a guess, is it similar to how a function works, in that the mysql_add_user.sh is written with the $USER variable in place,....and it just takes the actual user name and does its job?
Similar - $USER is a standard environment variable containing the user's login name, which should be set at login. If it is passed to the script as the first command line argument, it will be available in the script as the positional variable $1.
Actually, as it is an environment variable, it will be inherited by the add user script, but I generally find it clearer to pass arguments explicitly.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.