LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Automatic Execution of Script After Logging In (https://www.linuxquestions.org/questions/linux-newbie-8/automatic-execution-of-script-after-logging-in-4175419468/)

shiftshifter 07-30-2012 10:22 PM

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.

chrism01 07-30-2012 10:38 PM

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.

shiftshifter 07-31-2012 10:25 AM

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!

lithos 07-31-2012 11:39 AM

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 .

chrism01 07-31-2012 06:01 PM

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

shiftshifter 08-01-2012 12:38 PM

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!

AwesomeMachine 08-01-2012 12:49 PM

He means like Ubuntu, Debian, Fedora, Red Hat, etc.

shiftshifter 08-01-2012 03:12 PM

To Awesome Machine:
I see. Thanks for the information.

To lithos:
I am using Ubuntu.

chrism01 08-01-2012 05:48 PM

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/

shiftshifter 08-02-2012 01:37 AM

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.


All times are GMT -5. The time now is 06:54 AM.