Am i supposed to edit xinitrc to run a command at startup?
Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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.
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.
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!
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!
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.
#!/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
# 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
# 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
# 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!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.