Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I understand shell executes commands in either ~/.bash_profile, ~/.bash_login or ~/.profile, whichever is found first. My system has only .profile, yet commands entered there won't get executed on startup/login.

The script I'm talking about is essentially a cron front-end/TO-DO list manager. When user logs in (as in user gets access to his personal files/logs in to his account), the script should execute, checking whether there are any tasks that have failed to remind. If it finds any, zenity prompt will be poped up, asking next input.

share|improve this question

migrated from stackoverflow.com Dec 10 '12 at 23:17

This question came from our site for professional and enthusiast programmers.

1  
You can create ~/.bash_login if it doesn't exist. –  theabraham Dec 10 '12 at 22:47
    
~/.bash_login still doesn't work. –  Laur Aliste Dec 10 '12 at 23:03
1  
how do you test if it doesn't work? have you tried inserting an echo something... into ~/.profile and executing bash -l? –  mata Dec 10 '12 at 23:15
    
Be sure your scripts are executable. You can set this using chmod +x. –  Nicole Hamilton Dec 10 '12 at 23:21
1  
@NicoleHamilton afaik those setting files don't need to be executable. –  Laur Aliste Dec 10 '12 at 23:32

2 Answers 2

First create your ~/.bash_login and make it do something simply (like echo a phrase.)

echo "echo Look at me go" > ~/.bash_login

Then use bash -l like @mata said. The -l flag will run the bash as if it were the login shell (to make sure it reads your settings files.)

share|improve this answer
    
Works with bash -l but not after reboot/logon. –  Laur Aliste Dec 10 '12 at 23:30
    
try putting it in the ~/.bash_rc file, and see if that works. –  theabraham Dec 10 '12 at 23:32
    
If you mean ~/.bashrc, then already tried that. –  Laur Aliste Dec 10 '12 at 23:33
2  
@LaurAliste, please precisely define login. What commands exactly need to be ran? Is this for mounting filesystems or something? If you need something to be used be ran for every 'login' irrespective, of what shell or program is actually performing the login, then you need to look at doing something with PAM. –  Zoredache Dec 11 '12 at 0:11
1  
BTW, please update your question with additional details, and requirements. –  Zoredache Dec 11 '12 at 0:14
up vote 1 down vote accepted

Okay, I've found a solution to my initial problem. It's dirty one though.

First of all, using ~/.bash_profile, ~/.bash_login, ~/.profile or even /etc/profile.d/ should be preferred methods instead (here's good reading on the subject). Don't know why it doesn't work for me; perhaps it has something to do with my display manager auto logon workaround, just a guess.

Another solution would be adding script shortcuts to global file that gets executed at startup, for instance /etc/rc.local.

Since my script requires xserver and user to be logged on, I created initfile which waits after bootup for xserver and user to be logged on and then executes the script:

#! /bin/bash

### BEGIN INIT INFO
# Provides:          script_file.sh startup at boot
# Required-Start:    $all
# Required-Stop:
# X-Start-Before:    
# Default-Start:     2 3 4 5
# Default-Stop:
# Description: runs '/usr/local/bin/script_file.sh --optional --flags' at startup, when xserver has started and YOURUSERNAME is logged on.
### END INIT INFO

case "$1" in
    start)
        # Wait until X is running and required user logged in:
        count=0
        until [[ "$(tty)" != "\/dev\/tty1" ]] && [[ "$(who | cut -d' ' -f1 | sort | uniq)" == "YOURUSERNAME" ]]; do
            sleep 5
            let count=$count+1
            if [[ "$count" == "10" ]]; then
                echo "Xserver hasn't started or other error occurred. Abort"; exit 1
            fi
        done
        # Run the script as YOURUSERNAME instead of root:
        su - YOURUSERNAME -c '/usr/local/bin/script_file.sh --optional --flags'
    ;;
    stop)
        :
    ;;
esac
exit 0

This soulution assumes having automatic log-on set up. As mentioned, it really isn't the way to do it, but works for now.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.