LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 11-22-2009, 01:56 PM   #1
Karas
Member
 
Registered: Oct 2009
Distribution: Slackware 13.0
Posts: 49

Rep: Reputation: 15
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.
 
Old 11-22-2009, 02:23 PM   #2
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
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:
Code:
sed -i '/add_mysql_user/d' /home/$USER/.profile

Last edited by Robhogg; 11-22-2009 at 02:31 PM.
 
Old 11-22-2009, 02:32 PM   #3
Karas
Member
 
Registered: Oct 2009
Distribution: Slackware 13.0
Posts: 49

Original Poster
Rep: Reputation: 15
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?

Thanks.
 
Old 11-22-2009, 02:49 PM   #4
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
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 View Post
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.

More on Shell Scripting from the Rute Users' Guide.

Last edited by Robhogg; 11-22-2009 at 02:52 PM.
 
Old 11-22-2009, 03:06 PM   #5
Karas
Member
 
Registered: Oct 2009
Distribution: Slackware 13.0
Posts: 49

Original Poster
Rep: Reputation: 15
Awesome. That sounds all gravy. However now I am having trouble with granting myself privileges....Can you shed any light?


UPDATE:

I've fixed it now, thank you for your help!

Last edited by Karas; 11-22-2009 at 03:12 PM. Reason: Solved
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is a script, run at boot time from init.d, run with root authority? tmbrwolf53 Linux - Server 2 03-31-2007 09:15 PM
How do I make a simple script and make it run on bootup?? coolblue Programming 5 12-18-2006 10:55 PM
shell script to make a program run for a certain time Valkyrie_of_valhalla Programming 4 08-01-2006 07:09 PM
Run script each time cd is used c19h28O2 Linux - Newbie 14 05-02-2006 05:19 PM
how do i make a script run on login? roseplant SUSE / openSUSE 11 01-24-2006 05:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration