LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 02-25-2010, 01:18 PM   #1
kefi
LQ Newbie
 
Registered: Feb 2010
Location: Detroit, MI
Distribution: Gentoo
Posts: 7

Rep: Reputation: 0
Shell script executed on login


Hello everyone;

I am fairly new to Linux and am quite new to Gentoo. A month ago, I was using Ubuntu, but I wanted more control of my system. I switched to Debain and then again wanted a more custom kernel... I decided to use Gentoo.

Anyway, I want to execute a shell script when <user1> (and only <user1>) logs on. I am assuming there's either a place to place such a file or an already existing "dot" file. I just don't know about it and haven't been able to find an answer searching Google.

If nothing else, I am willing to use 'whoami' to determine if the logged on user is <user1>, but I still don't know where to place such a file.

Thanks in advance.
 
Old 02-25-2010, 01:29 PM   #2
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,981

Rep: Reputation: 388Reputation: 388Reputation: 388Reputation: 388
What, if any, gui are you using, eg kde, gnome, etc.? Most have a system for running scripts or applications on login by a user.
 
Old 02-25-2010, 01:36 PM   #3
fylnq
LQ Newbie
 
Registered: Feb 2010
Posts: 23

Rep: Reputation: 16
See this.

"When Bash is invoked as an interactive login shell, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable."
 
Old 02-25-2010, 01:45 PM   #4
kefi
LQ Newbie
 
Registered: Feb 2010
Location: Detroit, MI
Distribution: Gentoo
Posts: 7

Original Poster
Rep: Reputation: 0
@fylnq: so add something like: "exec ~/script_name.sh &" to ~/.bash_login?

@kilgoretrout: I am using Fluxbox, but <user1> will be using XFCE4.

Thanks for the quick responses!
 
Old 02-25-2010, 01:49 PM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by kefi View Post
@fylnq: so add something like: "exec ~/script_name.sh &" to ~/.bash_login?
That would replace the shell with ~/script_name.sh. If that's what you want to do it can be done by configuring the user's entry in /etc/passwd with <full path to>/script_name.sh
 
Old 02-25-2010, 01:52 PM   #6
kefi
LQ Newbie
 
Registered: Feb 2010
Location: Detroit, MI
Distribution: Gentoo
Posts: 7

Original Poster
Rep: Reputation: 0
@catkin: I don't want to replace the shell with ~/script_name.sh. I want the shell to run ~/script_name.sh when <user1> logs in.
 
Old 02-25-2010, 02:45 PM   #7
kefi
LQ Newbie
 
Registered: Feb 2010
Location: Detroit, MI
Distribution: Gentoo
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks to everyone who provided input.

This was easier than I expected. All I needed to do was edit my ~/.bash_login like so:

#!/bin/sh
./script_to_execute.sh

And the problem is solved.
 
Old 02-26-2010, 03:48 AM   #8
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Note that the user is free to change his shell of choice, rendering this useless. Note as well that the user is perfectly free to edit bashrc as you did, with similar results.

There's nothing wrong in this solution, just bear in mind that it won't work in situations where you don't trust the user.

In such situations you would need to look at the authentication system, usually pam.
 
Old 02-26-2010, 04:25 AM   #9
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by i92guboj View Post
There's nothing wrong in this solution, just bear in mind that it won't work in situations where you don't trust the user.

In such situations you would need to look at the authentication system, usually pam.
Or make user-specific changes in a file the user can't change -- /etc/profile or something it sources (messy -- there should (TM) be nothing user-specific in a global file).
 
Old 02-26-2010, 09:30 AM   #10
kefi
LQ Newbie
 
Registered: Feb 2010
Location: Detroit, MI
Distribution: Gentoo
Posts: 7

Original Poster
Rep: Reputation: 0
@i92guboj - yes, the idea is not to change the shell the user uses. Instead, just run a process on logon.
 
Old 02-26-2010, 04:36 PM   #11
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by kefi View Post
@i92guboj - yes, the idea is not to change the shell the user uses. Instead, just run a process on logon.
I don't think you understood the point of my post.

~/.bash_login and ~/.bashrc are files that are sourced by bash (and by no other shell). Any given user can use the "chsh" command to change his/her login shell (to sh, zsh, ksh, csh or whatever other shell s/he wants). If a given user does that, then the contents of the bash initialization files will never be parsed, and hence your code will never be run.

If you meant that you know beforehand that the user is never going to do that then it's fine.
 
Old 02-27-2010, 08:09 AM   #12
kefi
LQ Newbie
 
Registered: Feb 2010
Location: Detroit, MI
Distribution: Gentoo
Posts: 7

Original Poster
Rep: Reputation: 0
@i92guboj - the aforementioned user (<user1>) is my girlfriend (a Windows users). I refuse to dual-boot windows on either of my computers but she doesn't like using FluxBox, and can hardly remember how to login. She's not going to attempt to change shells -- the script that is executed when she logs on just starts X and XFCE4, so she doesn't have to 'startx'. Like I said in my original post, I just needed to execute a shell script when the user logs on (via bash).

Thank you all for your input. And i92guboj, sorry if I was too vague in my original post(s).
 
Old 02-28-2010, 01:19 AM   #13
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Not vague, I couldn't know it was your girlfriend, and I didn't know how skilled that other user was going to be. I was just warning you about the hole in that method in case it was an issue for you. If it's not then you have one less thing to worry about, and you can just ignore that information for the time being.
 
Old 03-01-2010, 10:04 AM   #14
kefi
LQ Newbie
 
Registered: Feb 2010
Location: Detroit, MI
Distribution: Gentoo
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks
 
  


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
How to check in a script whether the shell is login or non login? frankie_DJ Programming 7 10-21-2015 10:09 AM
Shell Script at login soulxcavtor Linux - Software 3 06-05-2006 09:36 PM
Use a shell script to do login and other commands jpan Linux - General 15 01-12-2005 06:52 AM
Shell script login command? chup Linux - General 3 08-24-2003 06:43 PM
telnet login via shell script lethe Linux - General 8 05-13-2002 09:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 12:14 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
Open Source Consulting | Domain Registration