LinuxQuestions.org
Help answer threads with 0 replies.
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 09-23-2008, 02:56 AM   #1
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Rep: Reputation: 15
script after login


Hi all,

I want to run a script to make some system variables available for users that login, since when I only have them in my rcS, they are not available after a user logs in.

Since I work with embedded Linux, I don have a specific Distro installed, but it is like redhat.

I searched the forums and found a solution to change the .bashrc file, but it does't exist in my home directory. So I created a new one, but it's not really working. This is how it is looking like:


Code:
 #cat .bashrc
#.bashrc
#added to make exports from rcS available for user root.

export DISPLAY=:0
After searching some more I also found the /etc/profile to be a possible solution, so i added:

Code:
export DISPLAY=:0
This also doesn't work.

if I after login manually enter export DISPLAY=:0 my Xserver does work.

If it is not entered I get the following error when I want to use my Xserver:

Code:
# xclock
Error: Can't open display:
My rcS file looks the following:

Code:
# cat rcS
#!/bin/sh
#init script. Based on scripts in timesys-init package.

NEED_NETWORKING=
DEVDIR="/dev"

mkdev() {
    echo "--${DEVDIR}/$1"
    [ -e ${DEVDIR}/$1 ] && return 0
    mkdir -p ${DEVDIR}/$(dirname $1)
    mknod ${DEVDIR}/$1 $2 $3 $4
}

echo -n "remounting / read-write ... "
/bin/mount -o remount,rw /dev/root /
echo "done."

echo -n "mounting /proc ... "
/bin/mount -t proc proc /proc
echo "done."

echo -n "mounting /sys ... "
/bin/mount -t sysfs sys /sys
echo "done."


echo -n "cleaning out /tmp ... "
rm -rf /tmp
mkdir -m 1777 /tmp
echo "done."

echo "creating device nodes ..."


cd ${DEVDIR}

[ ! -e ${DEVDIR}/pts ] && mkdir ${DEVDIR}/pts
chmod 655 ${DEVDIR}/pts

/sbin/mdev -s # ask busybox to populate the rest of the devs

echo "done."

echo -n "mounting /dev/pts ... "
/bin/mount -t devpts devpts /dev/pts
echo "done."


if [ ! -e /root/.gpe/gpe-mini-browser/bookmarks ]; then
  mkdir -p /root/.gpe/gpe-mini-browser
  cp /usr/share/gpe-mini-browser/bookmarks  \
    /root/.gpe/gpe-mini-browser/bookmarks
fi

echo -n "bringing up networking ... "
ifconfig lo 127.0.0.1 up
if [ "$NEED_NETWORKING" ]; then
   ifconfig eth0 up
   udhcpc eth0 &
fi
echo "done."

echo -n "starting syslogd ... "
/sbin/syslogd
echo "done."

echo -n "starting klogd ... "
/sbin/klogd
echo "done."

echo -n "starting telnetd ... "
/usr/sbin/telnetd
echo "done."

#echo -n "starting httpd ... "
#start-stop-daemon --start --exec /usr/sbin/thttpd -- -C /etc/thttpd.conf -c "**.cgi"
#echo "done."

#echo -n "starting dbus ... "
#/etc/rc.d/init.d/messagebus start
#echo "done."

echo "mounting removable media ... "
if [ -e /dev/sda1 ]; then
   mount /dev/sda1 /media/usb && echo "/dev/sda1 mounted at /media/usb"
elif [ -e /dev/sda ]; then
   mount /dev/sda /media/usb && echo "/dev/sda mounted at /media/usb"
fi

if [ -e /dev/mmcblk0p1 ]; then
   mount /dev/mmcblk0p1 /media/mmc && echo "/dev/mmcblk0p1 mounted at /media/mmc"
fi
echo "done."

echo -n "unmuting sound device ... "
aumix -w 100 -v 100 -W 50
echo "done."

# gtk %postin fails so we do it again here...

update-gdk-pixbuf-loaders $MACHTYPE
update-gtk-immodules $MACHTYPE

export HOME=/root

# 
# 
# demo specific stuff

# first, calibrate
#if [[ `dmesg | grep touchscreen | grep input0` ]]
#then
#        echo "Touchscreen Device is /dev/event0"
#        export TSLIB_TSDEVICE=/dev/event0
#        ts_calibrate
#elif [[ `dmesg | grep Touchscreen | grep input1` ]]
#then
#        echo "Touchscreen Device is /dev/event1"
#        export TSLIB_TSDEVICE=/dev/event1
#        ts_calibrate
#else
#        echo "Touchscreen Device Not Found"
#fi
export TSLIB_TSDEVICE=/dev/event0

# then start the X server

Xfbdev -br -pn -mouse tslib -dpi 100 -rgba bgr -screen 640x480@90 :0 -noreset &
#  -fp /usr/share/X11/fonts/misc &
export DISPLAY=:0

#matchbox-session &

# Start simple ftpd
/etc/init.d/simple-ftpd start &
I hope anyone knows a solution,

Feel free to ask more question is my question was not specific enough,

Thanks in advance,

Jurrian Dubbeldam

Last edited by Jurrian; 09-23-2008 at 02:57 AM.
 
Old 09-23-2008, 08:50 AM   #2
arckane
Member
 
Registered: Sep 2005
Location: UK
Distribution: Gentoo/Debian/Ubuntu
Posts: 307

Rep: Reputation: 38
Assuming it runs through rc/init scripts at bootime, create a script in /etc/init.d and ln -s it in /etc/rc3.d/.

OK, that's not overly indepth but I'm on a time limit, sorry :|
 
Old 09-23-2008, 09:29 AM   #3
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by arckane View Post
Assuming it runs through rc/init scripts at bootime, create a script in /etc/init.d and ln -s it in /etc/rc3.d/.
I created a script in /etc/init.d, however I dont have a dir /etc/rc3.d. I do have rc.d, but I dont think it's the same dir. Can I use rc.d or should I create rc3.d?

And what do you mean with ln -s in rc3.d? Should I just go to rc3.d (or rc.d) and enter ln -s? Or am I missing something?
 
Old 09-30-2008, 02:00 AM   #4
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Original Poster
Rep: Reputation: 15
Still can't find a solution to my problem, anyone here that can help me??
 
Old 09-30-2008, 02:06 AM   #5
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
The .bashrc solution entirely depends on two things:

1.- the shell you use
2.- the way you login

1) bashrc is an init file for bash. If you use another shell (regular sh, csh, ksm, zsh...) then bashrc will not be valid. Check the man page for your shell to get more info about the rc files for that shell. Usually you can find the shell you are running by doing this in command line:

Code:
echo $SHELL
2) depending on how do you login, the rc files that are sourced are not always the same. This is true at least for bash. For example, bash reads ~/.bashrc when you open it in non-login interactive mode, but it doesn't read that file when it is a login shell. So, the file you want to put that into is different depending on how you are starting your shell. More info on the bash man page:

Code:
man bash
 
Old 09-30-2008, 03:16 AM   #6
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Original Poster
Rep: Reputation: 15
if I execute the command $SHELL I get the following result:

Code:
# echo $SHELL
/bin/bash
searching the man bash page informs me that bash uses the following loginscripts if they exist:

Code:
Invoked as an interactive login shell, or with --login

When Bash is invoked as an interactive login shell, or as a non-interactive shell with the --login
option, 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. The --noprofile option 
may be used when the shell is started to inhibit this behavior.

When a login shell exits, Bash reads and executes commands from the file ~/.bash_logout, if it 
exists.
I don't have a .bash_login, or bash_profile. I do have etc/profile and .profile:

Code:
# cat /etc/profile
# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

pathmunge () {
        if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
           if [ "$2" = "after" ] ; then
              PATH=$PATH:$1
           else
              PATH=$1:$PATH
           fi
        fi
}

# ksh workaround
if [ -z "$EUID" -a -x /usr/bin/id ]; then 
        EUID=`id -u`
        UID=`id -ru`
fi

# Path manipulation
if [ "$EUID" = "0" ]; then
        pathmunge /sbin
        pathmunge /usr/sbin
        pathmunge /usr/local/sbin
fi

# No core files by default
ulimit -S -c 0 > /dev/null 2>&1

if [ -x /usr/bin/id ]; then
        USER="`id -un`"
        LOGNAME=$USER
        MAIL="/var/spool/mail/$USER"
fi

HOSTNAME=`/bin/hostname`
HISTSIZE=1000

if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
    INPUTRC=/etc/inputrc
fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

for i in /etc/profile.d/*.sh ; do
    if [ -r "$i" ]; then
        . $i
    fi
done

unset i
unset pathmunge

#set DISPLAY variable correct
export DISPLAY=":0"
Code:
# cat .profile
#make display variable visible
export DISPLAY=:0
But still when I login I don't have a display variable...

Anyone with a suggestion?

Thanx,

Jurrian

Last edited by Jurrian; 09-30-2008 at 03:29 AM.
 
Old 09-30-2008, 03:30 AM   #7
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
The bash startup file ~/.profile is sourced after first attempting either ~/.bash_profile or ~/.bash_login. See INVOCATION in man bash. This is useful to read, because as i92guboj mentioned, which file is source depends on whether the shell is a) interactive, b) a login shell.

You can create a .profile or .bash_profile, but your don't need both.
 
Old 09-30-2008, 03:38 AM   #8
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Original Poster
Rep: Reputation: 15
I have read the man page, but i guess i am understanding something wrong.

This is how I think it works:

I boot my target, which starts linux after the bootloader did it's work. When linux is booted I can login, so I login on root (no other account available yet), and bash starts.

So I guess bash is invoked as an interactive login shell. so it would read /etc/profile and ~/.profile, since I don't have ~/bash_login and ~/bash_profile.

So I created a file ~/.profile, but it still is not working..

Code from ~/.profile:

Code:
# cat ~/.profile
#make display variable visible
export DISPLAY=:0
Thans for all replies

Jurrian
 
Old 09-30-2008, 06:19 AM   #9
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Original Poster
Rep: Reputation: 15
Perhaps the problem is that I run busybox instead of bash??

But when I enter echo $SHELL the reply is /bin/bash. So I guess I have to use bash??

Thanx,

Jurrian
 
Old 09-30-2008, 11:49 AM   #10
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
Login as root, and create 4 startup files for root, by running the following commands (caution, they will replace root's startup files):

Code:
echo "echo BASH_PROFILE" >| ~/.bash_profile
echo "echo BASH_LOGIN" >| ~/.bash_login
echo "echo PROFILE" >| ~/.profile,
echo "echo BASHRC" >| ~/.bashrc
Log out and log in again. What is output?

The SHELL environment indicates your preferred choice of shells to use for applications that spawn a shell, if such applications interrogate $SHELL. It does not indicate what SHELL you must use.
 
Old 10-01-2008, 08:42 AM   #11
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Note also that order is relevant. Let me explain. If you run on a login interactive mode, bash reads /etc/profile, and after that, it looks for three files:

~/.bash_profile
~/.bash_login
~/.profile

In that very same order, and ONLY one is sourced if found: the first one. That means that, if there's a ~/.bash_profile, bash will stop looking, even if that file is empty, so ~/.bash_login and ~/.profile will be ignored. If there's no ~/.bash_profile but there's a ~/.bash_login, it will be read, and ~/.profile will be ignored if it exists. ç



About busybox, I never used it as my main shell, and I can't seem to find any real documents about the sh functionality. I'd just use a regular shell like bash.
 
Old 10-02-2008, 01:40 AM   #12
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Original Poster
Rep: Reputation: 15
Mr. C. This is my output:

Code:
 
192.168.0.253 login: root
Password: 


BusyBox v1.9.1 (2008-04-11 15:22:42 EDT) built-in shell (ash)
Enter 'help' for a list of built-in commands.

#
When I look to the created scripts they do have the commands they should. (echo and then the file name)

Could you tell me what the >| operator exactly does? I understand that with echo it will be placed in the file name after >|, or is that the only thing the >| operator specifies, in which file it has to be placed?

i92guboj, I want to keep my linux as small as possible, so I use busybox instead of a complete bash.

Thanx in advance,

Jurrian
 
Old 10-02-2008, 01:47 AM   #13
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
Notice your shell :

Code:
BusyBox v1.9.1 (2008-04-11 15:22:42 EDT) built-in shell (ash)
See man ash, searching for Invocation. Ash uses /etc/profile and .profile if they exist, and the environment variable ENV, but read the man page section for details.

The >| operator is redirect with overwrite.

Last edited by Mr. C.; 10-02-2008 at 01:50 AM.
 
Old 10-02-2008, 02:12 AM   #14
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
Since you created the .profile, and upon login you did not see PROFILE, either the .profile was not created in root's home directory, or the ash shell is not a login shell. Look at the output of ps, searching for ash. Does the ash command name in the ps output begin with a dash character (eg. -ash)? This would indicate the ash shell was a login shell, and /etc/profile and $HOME/.profile would be used. Otherwise, they are not. Again, see Invocation.
 
Old 10-02-2008, 02:18 AM   #15
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Original Poster
Rep: Reputation: 15
Hi,

At least that makes me feel coming more in the correct direction.

After reading the invocation from man ash,

I found out it uses /etc/profile or /etc/.profile, and with the ENV variable you can set a path to a new file.

So I created a ENV=$HOME/.profile in the /etc/profile, and I exported the DISPLAY variable in ~/.profile.

However, still no DISPLAY variable when I echo $DISPLAY...

My /etc/profile script:

Code:
# cat /etc/profile
# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc



pathmunge () {
        if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
           if [ "$2" = "after" ] ; then
              PATH=$PATH:$1
           else
              PATH=$1:$PATH
           fi
        fi
}

# ksh workaround
if [ -z "$EUID" -a -x /usr/bin/id ]; then 
        EUID=`id -u`
        UID=`id -ru`
fi

# Path manipulation
if [ "$EUID" = "0" ]; then
        pathmunge /sbin
        pathmunge /usr/sbin
        pathmunge /usr/local/sbin
fi

# No core files by default
ulimit -S -c 0 > /dev/null 2>&1

if [ -x /usr/bin/id ]; then
        USER="`id -un`"
        LOGNAME=$USER
        MAIL="/var/spool/mail/$USER"
fi

HOSTNAME=`/bin/hostname`
HISTSIZE=1000

if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
    INPUTRC=/etc/inputrc
fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

for i in /etc/profile.d/*.sh ; do
    if [ -r "$i" ]; then
        . $i
    fi
done

unset i
unset pathmunge

ENV=$HOME/.profile;
export ENV
And my ~/.profile script:

Code:
# cat ~/.profile
export DISPLAY=:0
What am I doing wrong now? And why does the $SHELL variable indicates I'm using bash. while I'm actually using ash?

Thanx in advance,

Jurrian
 
  


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 11:09 AM
login script btaylor1988 Linux - Server 8 09-12-2007 09:22 AM
Need a login script stefaandk Linux - Newbie 4 01-05-2006 05:24 PM
login script nin881 Slackware 3 06-11-2005 03:21 AM
Login script unclejessie77 Programming 5 02-24-2005 01:30 PM


All times are GMT -5. The time now is 09:42 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