LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-30-2003, 02:41 PM   #1
Tyir
Member
 
Registered: Sep 2003
Distribution: Slackware 9.1 with fluxbox
Posts: 259

Rep: Reputation: 30
Am i supposed to edit xinitrc to run a command at startup?


the file /etc/X11/xinit/xinitrc...is that the file we are supposed to edit to have acommand run at startup?

and if so, where are we suppoed to add the line? at the bottom?

Thanks
 
Old 10-30-2003, 02:51 PM   #2
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
The one in /etc/X11/xinit is a global xinitrc file, and probably should be left alone. Each user also has an ~/.xinitrc file (don't forget the dot), which lists things to start for each user. Depending on your setup, though, it might be skipped - for example, if you have a graphical login screen like GDM or KDM, it may not look at your ~/.xinitrc file.
 
Old 10-30-2003, 02:52 PM   #3
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
What kind of command? An app to run at startup? You should edit ~/.xinitrc or copy /etc/xinitrc to that and edit the personal one if one isn't already there. Don't have to, of course. And you put it before the last command - the 'exec' - in whatever order you'd like. If it's a different command, though, we may be talking about other stuff.
 
Old 10-30-2003, 04:14 PM   #4
Tyir
Member
 
Registered: Sep 2003
Distribution: Slackware 9.1 with fluxbox
Posts: 259

Original Poster
Rep: Reputation: 30
The command is this...
xmodmap -e "pointer = 1 2 3 6 7 4 5"

i have to do this because i was tryign to enaable my side mouse buttons (on a MS Explorer) but i couldn never get ti to work correctly

anyway now i need to run this each time i restart to get my scroll working
 
Old 10-30-2003, 10:31 PM   #5
Tyir
Member
 
Registered: Sep 2003
Distribution: Slackware 9.1 with fluxbox
Posts: 259

Original Poster
Rep: Reputation: 30
So if i want the commard to run when I start-up...where should I put it?

It doesnt wokr when i put it in ~/.xinitrc
this is what it is:

#!/bin/bash
xmodmap -e "pointer = 1 2 3 6 7 4 5"
imwheel -k -b -p "67"
 
Old 10-31-2003, 06:51 AM   #6
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Damn that's a lotta buttons.

Okay, that's actually just its own scriptlet? And 'imwheel' is a binary of some kind? I'm afraid I don't understand the script, so I'm not sure how to answer. But you say it works when you run it manually, so it's just an issue of automating it.

Do you default to a graphical login screen or do you run X/K/G-DM, like wapcaplet says? Then there's probably some ?DM file you'd need to edit, or possibly Xsession or whatever it is. If you go to a true command line and start X by 'startx', I don't see why it wouldn't work there, though.

Maybe wapcaplet or somebody will come back by - he knows a lotlot more than I do.
 
Old 10-31-2003, 12:02 PM   #7
Tyir
Member
 
Registered: Sep 2003
Distribution: Slackware 9.1 with fluxbox
Posts: 259

Original Poster
Rep: Reputation: 30
yea..I have a graphical login screen..so I'm assuming that is why the ~/.xinitrc doesn't get run...
Then where am I supposed to put the script?

yes, 7 buttons on mouse
left, centre, right, wheel up/down and 2 sides
 
Old 10-31-2003, 03:10 PM   #8
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Hm. I was reading Xsession, thinking you could maybe stick it in there (and maybe you can) but it looks like you can create that file as an '~/.xprofile'. So I'd try that - save that file as ~/.xprofile. If that doesn't work, check out the man page for the syntax of ~/.Xmodmap, maybe. I don't think that one's supposed to be an executable script - it's just read in - but I don't know. Plus, you've got that second line. Hopefully ~/.xprofile will work.
 
Old 10-31-2003, 03:19 PM   #9
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Quote:
Originally posted by digiot Maybe wapcaplet or somebody will come back by - he knows a lotlot more than I do.
Heh, hardly! I can't even figure out how to get GKrellm to start up when I login from KDM.

Here's what I do know (or am figuring out as I type this). Some of this stuff might be Mandrake-specific, since I'm just seeing what's on my box, but hopefully it helps...

From what I understand, your ~/.xinitrc must be looked at and used if you start X from the command line using 'startx' (which in turn calls xinit - the startx and xinit man pages explain some of this). But I also gather that GUI logins like GDM and KDM have a different way of getting X up and running, using their own muddleheaded configuration schemes.

KDM (and the rest of KDE), apparently, have decided they're too good to keep their configuration files in /etc like everyone else, so they are located in /usr/share/config. Most of this can probably be configured with kcontrol (the KDE control center). I am not entirely certain what procedure KDM uses for getting X started. (Wouldn't it be great if KDM had a manual page like everything else does?) I would assume there is some chain of scripts that get executed, eventually ending with running KDE itself. Somewhere in the middle, it should be possible to add your own scripts to be run. Check out some of the stuff in /usr/share/config/kdm if you are running KDM. I'm interested in figuring out how to get GKrellm to run on startup anyway, so I'll let you know if I figure anything out.

GDM, on the other hand, does follow precedent and keep its config stuff in /etc/X11/gdm. I seem to recall similar problems getting stuff to run from a GDM login, but one place you might want to start is in /etc/X11/gdm/Sessions. There is a list of the various window managers; when you choose one of those from GDM, I am fairly sure that it runs the script in that folder. Those, in turn, run the script /etc/X11/xdm/Xsession with your preferred window manager as an argument (which you can see if you view the contents of the window manager startup scripts). Anyhoo, so now we check out /etc/X11/xdm/Xsession, which looks like all it does is call /etc/X11/Xsession. (Follow the bouncing ball...) Ah, now /etc/X11/Xsession looks to be the real workhorse script. It does all sorts of setup stuff... gets any resource information you may have in your ~/.Xresources and ~/.Xdefaults files... runs any scripts that are in /etc/X11/xinit.d... Then it tries to launch the requested window manager, and if it's not available, it tries a number of fail-safe alternatives (like icewm and twm). Whew! Of course, looking at this, nowhere does it seem to be running anything found in ~/.xinitrc. The final script that gets run from here is the one which starts your window manager, which is probably something like /usr/bin/startkde, /usr/X11R6/bin/startblackbox, or whatever. You could edit those scripts to run what you want, but it'll be on a system-wide basis, and not per-user, which is the whole point of ~/.xinitrc.

SO... what you need to do (and what I need to do, also) is figure out a nice flexible way of getting KDM/GDM to execute the commands we want (xmodmap in your case, gkrellm in my case), or better yet, run a specific script in our home directory, which works on a per-user basis (so any user can take advantage of it), and which isn't window-manager-specific, so it will work no matter which window manager we want to use today. Unfortunately, I have no idea how to do that right at the moment... probably adding something to /etc/X11/Xsession would be the way to go. Maybe something like that already exists and I haven't found it... I will work on it and get back to you.
 
Old 10-31-2003, 04:59 PM   #10
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Quote:
Originally posted by digiot
Hm. I was reading Xsession, thinking you could maybe stick it in there (and maybe you can) but it looks like you can create that file as an '~/.xprofile'. So I'd try that - save that file as ~/.xprofile.
Hm, my Xsession does not make any reference to an .xprofile (at least not in Mandrake 9). However, I have determined a way to make it do so. After using lots of echo statements to see what Xsession is doing, I've found that this block of code is what matters:

Code:
if [ -n "$DESKTOP" ]; then
    case $DESKTOP in
        failsafe)
        xsetroot -cursor_name left_ptr
        exec $SSH_AGENT xvt -geometry 80x24-0-0
        exec $SSH_AGENT xterm -geometry 80x24-0-0
        exec $SSH_AGENT twm
        ;;
        default)
        ;;
        *)
        exec $SSH_AGENT /bin/sh -c "$(/usr/sbin/chksession -x=$DESKTOP)"
        ;;
    esac
fi
The last 'exec' statement is what launches the window manager. chksession apparently gives the name of an executable startup script if you give it the name of a window manager. Give it 'KDE' and it says to run /usr/bin/startkde. Give it a bogus name and it will give you a failsafe WM like twm. Anyways, just above that exec statement, I added these three lines:

Code:
if [ -x "$HOME/.xprofile" ]; then
    . $HOME/.xprofile
fi
Now, if a .xprofile exists in the user's home directory, it gets executed before launching the window manager script. I put 'gkrellm -w &' in my ~/.xprofile, and bingo! Instant gkrellm on startup. You could put whatever commands you want in there; it should probably be executable, and have the '#!/bin/sh' at the top, though I'm not sure about that.

This works with KDM, at least. It should work for GDM, but due to another problem I'm not concerned about fixing today, GDM likes to make my Blackbox fonts all wacky. At any rate, I hope this helps you. Cheers!
 
Old 11-01-2003, 12:13 PM   #11
Tyir
Member
 
Registered: Sep 2003
Distribution: Slackware 9.1 with fluxbox
Posts: 259

Original Poster
Rep: Reputation: 30
Whew...looks good!
I'm going to try that out...I'm still pretty new but i think I understood...let me recap to clear it up..

I open up the script called /etc/X11/sdm/Xsession

Ok.......I didn't see that snipped you had...BUT this looks interesting!


userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
userxkbmap=$HOME/.Xkbmap

is near the top of Xsession

So....mabye all ihave to do is rename my .xinitrc file in my home to .Xmodmap
It seems that the script will look there....is that correct?
I will rename/restart and come back with answers!
 
Old 11-01-2003, 12:21 PM   #12
Tyir
Member
 
Registered: Sep 2003
Distribution: Slackware 9.1 with fluxbox
Posts: 259

Original Poster
Rep: Reputation: 30
nope didnt work.......
 
Old 11-01-2003, 01:51 PM   #13
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
I'm not certain, but I think that the Xresources, Xmodmap etc. are not actually executable scripts, but another kind of configuration file. So any commands that might be in them are probably not executed.

Is there anything in your Xsession that appears to be launching a window manager? Is 'chksession' used in yours? Actually, go ahead and post your Xsession file and maybe I can figure something out for you.
 
Old 11-01-2003, 06:35 PM   #14
Tyir
Member
 
Registered: Sep 2003
Distribution: Slackware 9.1 with fluxbox
Posts: 259

Original Poster
Rep: Reputation: 30
certainly...

#!/bin/bash
# Copyright (c) 1999-2002 Red Hat, Inc.

# redirect errors to a file in user's home directory if we can
errfile="$HOME/.xsession-errors"
if cp /dev/null "$errfile" 2> /dev/null ; then
chmod 600 "$errfile"
exec > "$errfile" 2>&1
else
errfile=`mktemp -q /tmp/xses-$USER.XXXXXX`
if [ $? -eq 0 ]; then
exec > "$errfile" 2>&1
fi
fi

if ! printenv PATH | grep -q /usr/X11R6/bin
then
PATH="${PATH}":/usr/X11R6/bin
fi

xsetroot -solid '#5477A0'

userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
userxkbmap=$HOME/.Xkbmap

sysresources=/etc/X11/Xresources
sysmodmap=/etc/X11/Xmodmap
sysxkbmap=/etc/X11/Xkbmap

# merge in defaults
if [ -f "$sysresources" ]; then
xrdb -merge "$sysresources"
fi

if [ -f "$userresources" ]; then
xrdb -merge "$userresources"
fi

# merge in keymaps
if [ -f "$sysxkbmap" ]; then
setxkbmap $(cat "$sysxkbmap")
XKB_IN_USE=yes
fi

if [ -f "$userxkbmap" ]; then
setxkbmap $(cat "$userxkbmap")
XKB_IN_USE=yes
fi

if [ -z "$XKB_IN_USE" -a ! -L /etc/X11/X ]; then
if grep '^exec.*/Xsun' /etc/X11/X > /dev/null 2>&1 && [ -f /etc/X11/XF86Config ]; then
xkbsymbols=`sed -n -e 's/^[ ]*XkbSymbols[ ]*"\(.*\)".*$/\1/p' /etc/X11/XF86Config`
if [ -n "$xkbsymbols" ]; then
setxkbmap -symbols "$xkbsymbols"
XKB_IN_USE=yes
fi
fi
fi

# xkb and xmodmap don't play nice together
if [ -z "$XKB_IN_USE" ]; then
if [ -f "$sysmodmap" ]; then
xmodmap "$sysmodmap"
fi

if [ -f "$usermodmap" ]; then
xmodmap "$usermodmap"
fi
fi
unset XKB_IN_USE

# run all system xinitrc shell scripts.
for i in /etc/X11/xinit/xinitrc.d/* ; do
if [ -x "$i" ]; then
. "$i"
fi
done

# is ssh-agent available?
SSHAGENT=
[ -x /usr/bin/ssh-agent ] && SSHAGENT="/usr/bin/ssh-agent"

# now, we see if xdm/gdm/kdm has asked for a specific environment
case $# in
1)
if [ -x /usr/share/apps/switchdesk/Xclients.$1 ]; then
exec -l $SHELL -c "$SSHAGENT /usr/share/apps/switchdesk/Xclients.$1";
fi;

case $1 in
failsafe)
exec -l $SHELL -c "xterm -geometry 80x24-0-0"
;;
gnome)
exec -l $SHELL -c "$SSHAGENT gnome-session"
;;
kde|kde1|kde2)
exec -l $SHELL -c "$SSHAGENT /usr/share/apps/switchdesk/Xclients.kde"
;;
twm)
# fall back to twm
exec -l $SHELL -c "$SSHAGENT /usr/share/apps/switchdesk/Xclients.twm"
;;
esac
esac

# otherwise, take default action
if [ -x "$HOME/.xsession" ]; then
exec -l $SHELL -c "$SSHAGENT $HOME/.xsession"
elif [ -x "$HOME/.Xclients" ]; then
exec -l $SHELL -c "$SSHAGENT $HOME/.Xclients"
elif [ -x /etc/X11/xinit/Xclients ]; then
exec -l $SHELL -c "$SSHAGENT /etc/X11/xinit/Xclients"
else
# should never get here; failsafe fallback
exec -l $SHELL -c "xsm"
fi
 
Old 11-01-2003, 07:33 PM   #15
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
It looks like you can add it here:

Code:
# now, we see if xdm/gdm/kdm has asked for a specific environment
case $# in
1)
    if [ -x /usr/share/apps/switchdesk/Xclients.$1 ]; then
       exec -l $SHELL -c "$SSHAGENT /usr/share/apps/switchdesk/Xclients.$1";
    fi;


    # Insert here:
    if [ -x "$HOME/.xprofile" ]; then
        . $HOME/.xprofile
    fi
                                                                                                     
    case $1 in
    failsafe)
       exec -l $SHELL -c "xterm -geometry 80x24-0-0"
       ;;
    gnome)
       exec -l $SHELL -c "$SSHAGENT gnome-session"
       ;;
    kde|kde1|kde2)
       exec -l $SHELL -c "$SSHAGENT /usr/share/apps/switchdesk/Xclients.kde"
       ;;
    twm)
        # fall back to twm
       exec -l $SHELL -c "$SSHAGENT /usr/share/apps/switchdesk/Xclients.twm"
       ;;
    esac
esac
Then add whatever you like to ~/.xprofile as before. Let me know if that works!
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I edit .xinitrc? JohnStormrider Linux - Newbie 6 09-02-2005 06:19 PM
xinitrc in libranet? how do i execute a command on x startup? bleargh Linux - Software 6 12-11-2004 11:00 PM
make a command run at startup? cheater1034 Linux - General 2 09-12-2004 05:51 AM
How can I run a command automatically at startup? luwigie Linux - General 8 08-26-2004 09:05 PM
When I edit .xinitrc, X will not start... QtCoder Slackware 2 11-09-2003 10:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:05 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
Open Source Consulting | Domain Registration