How can my script tell if I am in the console?

How can my script tell if I am in the console?

Post by Lars Eighne » Sat, 23 Mar 2002 20:29:51



I use zgv to display images when I am in the console (ttyv0).
This won't work if I am in another ttyv.

I want to write a script to use zgv to display a picture if I
am in the console and xzgv if I am in X.  I want it to bail
otherwise (i.e. if I am in another ttyv).

I want this script (showpics) to be mapped to image/* in
.mailcap and in lynx.

I know I can test $DISPLAY to see if I am in X (it isn't set
if I am in a ttyv.

However, tty doesn't tell me if lynx or the mail program I am
using is running in ttyv0.

Here is my attempt at the script:

#!/bin/sh
#show-pics

ISCONSOLE=`tty`

if [ "$DISPLAY" = "" ];
then
#if [ "$ISCONSOLE" = "/dev/ttyv0" ];
#then
zgv $1
else
echo not in console
fi
else
xzvg $1
fi

#end

This works fine from the command line.  But 'tty' returns
"not a tty" when this script is invoked by lynx, etc.  I
gather this doesn't work because STANDARD INPUT is then
something else.  What I need to know is whether lynx or
whatever is running in the console so that zgv will
succeed.  How can my script tell?

--

 It's important for us to explain to our nation that life is important. It's
 not only life of babies, but it's life of children living in, you know, the
 dark dungeons of the Internet.--G.W. Bush, Arlington Heights, Ill.,10/24/00

 
 
 

How can my script tell if I am in the console?

Post by sake » Tue, 26 Mar 2002 19:50:06


Hi,

from what i understand when you write of "invoked by lynx"
you mean the script is part of a web page and invoked by
a browser client (cgi thing).

The invoked script will inherit the enviroment from
the web server wich is not attached to a terminal as most
of the daemons in the standard config.

if the above asummption is correct you will have to
either get the tty of the client browser or you will have to
do a two step: write picutre into file and then present it
on the web (i have no experiences with zgv what so ever).

You should also take look at
comp.unix.shell
comp.infosystems.www.authoring.cgi

hope this heps
sake.

...
...

Quote:

> This works fine from the command line.  But 'tty' returns
> "not a tty" when this script is invoked by lynx, etc.  I

...

 
 
 

How can my script tell if I am in the console?

Post by Lars Eighne » Tue, 26 Mar 2002 21:42:53



lovely and talented sake broadcast on comp.unix.bsd.freebsd.misc:

Quote:> Hi,
> from what i understand when you write of "invoked by lynx"
> you mean the script is part of a web page and invoked by
> a browser client (cgi thing).

No.  What I mean is a web page has a link to an image, lynx can
identify the MIME type from the file extension, and I want lynx to
call something to display the image, all of this being done client
side.  The server has nothing to do with except to serve the image in
the ordinary way when lynx asks for it.  The thing that can display
the image when lynx is in the console is zgv.  In X lynx is usually
configured to use xv to display images.  Lynx can be configured to
use various handlers for various MIME types or it will use the
handlers in mailcap or .mailcap if it can find either of these.  The
special problem with images is that image handlers require graphics
modes, which the console can reach but other ttyvs can't.  This is
why a script has to be written to test for the console before
actually launching the graphics handler.

Quote:> The invoked script will inherit the enviroment from
> the web server wich is not attached to a terminal as most
> of the daemons in the standard config.

Well, I settled for the cheap hack (I often do) and
test for ttyv0 on login, setting $CONSOLE if true.

Since all of this is client-side, the client-side
environment is what counts, and I cannot see anything
in the environment that my shell (BASH) automatically
sets that will tell me whether I am in the console.

Quote:> if the above asummption is correct you will have to
> either get the tty of the client browser or you will have to
> do a two step: write picutre into file and then present it
> on the web (i have no experiences with zgv what so ever).

I had to hack it for a while to convince it to run on FreeBSD.
It's a very swift image viewer for the console that relies on
the svgalib (with the security issues that entails for some
people).

Here is the running script.  (I will not advise anyone
how to hack zgv because I am not sure how horrible I
made things from a security standpoint.)

#!/bin/sh

#This is to handle images for lynx.  If in X, lynx shouldn't really
#use it and should be configured to call xzgv (or your favorite X
#image viewer) itself, but provision is made here for completeness.
#Zgv will only work in the console, so this should refuse to start in
#other ttyvs.  $CONSOLE is set in /ect/profile at login if login
#is on ttyv0.  

if [ "$DISPLAY" = "" ];
then
if [ "$CONSOLE" = "yes" ];
then
zgv -i -J 1 -k -z $1
else
echo not in console
fi
else
xzgv $1
#or your favorite X image viewer
fi

#end

Quote:> You should also take look at
> comp.unix.shell
> comp.infosystems.www.authoring.cgi
> hope this heps
> sake.

--

               War on Terrorism: Treat Readers like Mushrooms
 "If the story needs rewriting to play down the civilian casualties, DO IT."
                   -Memo, _Panama City_ (FL) _News Herald_
 
 
 

1. How can I tell whether I am logging in on console inside .login?

When I log in on the sun, 3 windows are opened. Each of these windows runs
the .login script, but certain commands (e.g. xsetbg) only need to run once.
In addition, when I log in from a remote location, I don't need to run these
commands.
Is there a simple way of telling how I am connected?
How would I implement it within a script, if it isn't totally self evident.
(Within my .login, I run a short shell script in the background which checks
whos logged in, gets the weather, etc.)
Thanx much in advance
Wonder Midget

2. Help! Help! Help!

3. Script running from command line or called by other script: how tell?

4. Solaris2.5 w/ exterm, Wnn, etc.

5. script to read a line in an array with , as IFS

6. Linux core file processing

7. How do I tell what speed I am connected at?

8. Printing 132x80 on HP LJ5000

9. rlogin can't tell who I am in Solaris 2.1

10. I am ready for Linus....Just tell me how to set it up!!!

11. can someone tell me what I am missing here?

12. Question: How can I tell what kernal I am presently running?