LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-30-2012, 10:22 PM   #1
shiftshifter
LQ Newbie
 
Registered: Jul 2012
Posts: 7

Rep: Reputation: Disabled
Automatic Execution of Script After Logging In


Hi All,

I'm new in using shell scripts. I managed to create a simple script that allows me to input and view schedules. I heard it's possible to setup a script to automatically run once I log in. I was hoping to have my schedules for the day display on the screen once I logged in. Say for example I logged in today and all my schedules for 07/31/2012 will be shown.

Thanks in advance for your reply.
 
Old 07-30-2012, 10:38 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,362

Rep: Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377
You could add that to the bottom of your .bash_profile file, which exists in your home dir eg
Code:
/home/you/.bash_profile
This gets run as you login.
 
Old 07-31-2012, 10:25 AM   #3
shiftshifter
LQ Newbie
 
Registered: Jul 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thanks for the swift reply. I hope this is mainly an error on my part but I can't seem to locate the bash profile. I found a .bash_history and .bash_log but no .bash_profile.

Thanks again!
 
Old 07-31-2012, 11:39 AM   #4
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
I think here you will find that mentioned "bash_profile" file.


You don't say which distro you are using, please provide more info about it .
 
Old 07-31-2012, 06:01 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,362

Rep: Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377
That would be odd unless you are not using the bash shell.
Can you grep your entry in /etc/passwd and double-check
Code:
echo $SHELL
 
Old 08-01-2012, 12:38 PM   #6
shiftshifter
LQ Newbie
 
Registered: Jul 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Hi,

When I tried "echo $SHELL" on the command line the output is /bin/bash. I've also managed to check the passwd in etc.

To lithos:
I'm sorry but what do you mean by distro and how could I check it?

Thanks again!
 
Old 08-01-2012, 12:49 PM   #7
AwesomeMachine
Senior Member
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 2,593

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
He means like Ubuntu, Debian, Fedora, Red Hat, etc.
 
Old 08-01-2012, 03:12 PM   #8
shiftshifter
LQ Newbie
 
Registered: Jul 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
To Awesome Machine:
I see. Thanks for the information.

To lithos:
I am using Ubuntu.
 
Old 08-01-2012, 05:48 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,362

Rep: Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377
If your entry in /etc/passwd says you are using bash, then normally you would have installed .bash_profile & .bashrc.
Basic versions are usually available in /etc/skel, although it may be different in Ubuntu.
See the link mentioned above http://www.cyberciti.biz/faq/howto-c...-user-account/

You can create them via an editor if necessary, with following perms/ownerships
Code:
-rw-r--r--  1 username usrgrp   260 Oct 18  2011 .bash_profile
-rw-r--r--  1 username usergrp   124 Sep 27  2011 .bashrc
Get the values for username, usergrp from your entry in /etc/passwd

Typical contents
Code:
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

# This seems to work
HOST=`hostname`
PS1='${LOGNAME}@${HOST}:${PWD}> '
export PS1

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific aliases and functions
and/or look in another user's home dir if possible.

Useful links
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
Old 08-02-2012, 01:37 AM   #10
shiftshifter
LQ Newbie
 
Registered: Jul 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
I've tried add the run command for my script at the end of .bashrc and it only works when I open terminal. It doesn't show after I logged in.

I also tried the same using .bash_profile and it has the same result.

I tried the suggestion from another site to include the run command for the script in the Startup Applications and still unsuccessful. Is this step not applicable to Ubuntu 12.04 LTS because that is what I'm using. Hopefully this is of the source of this issue.

I'll try adding the script in the /etc/init.d/ directory though a friend of mine said it doesn't work with his script.

Are there any other possible ways? I do remember when using Windows we had a autoexec.bat. Is there an equivalent of this kind of file in Ubuntu?

Hope to resolve this soon.
 
  


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
Remote execution of command to find available space logging in ftp mode. unixuser Linux - Newbie 3 10-09-2008 08:51 AM
Logging in and logging out of a server in a script frankie_DJ Linux - Newbie 4 01-27-2007 11:03 PM
Script execution salmanucit Linux - Software 1 12-08-2005 08:51 AM
Automatic execution of a command after login openart Linux - Newbie 5 10-29-2004 01:44 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM


All times are GMT -5. The time now is 01:58 PM.

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