Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 Dec 10 '12 at 23:17

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

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
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
@NicoleHamilton afaik those setting files don't need to be executable. – laur Dec 10 '12 at 23:32

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 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 Dec 10 '12 at 23:33
@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
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

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

case "$1" in
        # Wait until X is running and required user logged in:
        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
        # Run the script as YOURUSERNAME instead of root:
        su - YOURUSERNAME -c '/usr/local/bin/ --optional --flags'
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .