Mailing List Archive

Bash script won't logout user
I boot into init 3 (command line), and "startx &" manually when I need it.

The problem is that someone could simply switch VC terminals and login.

So I thought I'd write a little wrapper "x.sh" to startx and log me out of
the console. But it doesn't log me out?! If I switch back to the VC and type
"exit", I logout just fine. I've also tried to put "logout" there, and same
result.

daevid@locutus ~ $ cat /usr/local/bin/x.sh
---------- snip ------------
#!/bin/sh

# start X windows and force all the output to go to a log file
# instead of barfing on the screen.
/usr/X11R6/bin/startx > ~/.Xmsg.log 2>&1 &

# this will setup the fonts and such for gnome/gtk applications
# under other WMs, such as KDE
#ln -vs /usr/libexec/gnome-settings-daemon
~/.kde/Autostart/gnome-settings-daemon

clear

# this doesn't seem to work?!
exit


--
gentoo-user@gentoo.org mailing list
Re: Bash script won't logout user [ In reply to ]
Daevid Vincent wrote:

> So I thought I'd write a little wrapper "x.sh" to startx and log me out of

from the command line prompt, just type

exec startx

that will end your login session and start your X session. One of the
problems you might run into is that Gnome/KDE may not know to make
certain /dev files writable by you (/dev/dsp) if you run without a login
session.

gdm/kdm was designed for such a case however.

> #!/bin/sh
[snip]
> # this doesn't seem to work?!
> exit

you're only exiting from your script, not the shell. By running your
script via ./x.sh, you are in effect creating a sub-shell that runs your
script.

You could source your script instead of run it, and it should exit fine:

. ./x.sh

or

source ./x.sh

But again, you'd accomplish the same thing by exec'ing startx from the
prompt.

--
gentoo-user@gentoo.org mailing list
Re: Bash script won't logout user [ In reply to ]
Daevid Vincent wrote:
> So I thought I'd write a little wrapper "x.sh" to startx and log me out of
> the console. But it doesn't log me out?!

Well, since:

$ startx && logout


works. Why not just an alias?

$ alias xstart='startx && logout'

"exit" doesn't work in your script 'cos it just exits the script, not your
current session. And no, double exit won't work either ;)


Regards,
Norberto

--
gentoo-user@gentoo.org mailing list
Re: Bash script won't logout user [ In reply to ]
On Tue, Sep 14, 2004 at 03:37:20PM -0300, Norberto Bensa wrote:
> Daevid Vincent wrote:
> > So I thought I'd write a little wrapper "x.sh" to startx and log me out of
> > the console. But it doesn't log me out?!
>
> $ alias xstart='startx && logout'

Another possibility is

$ alias startx='exec /usr/X11R6/bin/startx'

since that won't leave the shell running. While the startx is still
attached to the terminal, it can't be suspended.

/jgt

--
gentoo-user@gentoo.org mailing list
Re: Bash script won't logout user [ In reply to ]
On 14 Sep 2004, at 11:23, Daevid Vincent wrote:
> I boot into init 3 (command line), and "startx &" manually when I need
> it.
>
> The problem is that someone could simply switch VC terminals and login.
>
> So I thought I'd write a little wrapper "x.sh" to startx and log me
> out of
> the console. But it doesn't log me out?! If I switch back to the VC
> and type
> "exit", I logout just fine. I've also tried to put "logout" there, and
> same
> result.
>
> daevid@locutus ~ $ cat /usr/local/bin/x.sh
> ---------- snip ------------
> #!/bin/sh
>
> # start X windows and force all the output to go to a log file
> # instead of barfing on the screen.
> /usr/X11R6/bin/startx > ~/.Xmsg.log 2>&1 &
>
> # this will setup the fonts and such for gnome/gtk applications
> # under other WMs, such as KDE
> #ln -vs /usr/libexec/gnome-settings-daemon
> ~/.kde/Autostart/gnome-settings-daemon
>
> clear
>
> # this doesn't seem to work?!
> exit

The issue is that "exit" from a shell script will exit the subshell
created
by the script, not the original one that the script was started from.
They
are separate.

You could try something like
> kill $PPID
instead.