Dear friends,
The following queries were still to be answered. One highly empathic
person, who replied by email (I guess he wanted privacy) took great time
and patience to reply to my novice questions. When I asked him whether I
should post our communications to the group-list he said he wanted me to
do it in my own words.
However, I do not hope to surpass his wisdom with my mere acquaintance
with the issue, and that too at a superficial level. So I am posting our
lines in a logically arranged manner. The credit for lucidity goes
entirely to our anonymous friend.
Regards
RajibBandopadhyay
...
>>
>> Perhaps it would be better to tell us what you are trying to
accomplish.
>>
>> There's bound to be a far better way for whatever it is that you're
>>
>> trying to do than doing it via cron.
>
> Was trying to see whether it is possible to launch a GUI application
with gnome-schedule.
Just read this thread. It doesn't seem to me your question was ever
answered.
When you login to a linux system you take ownership of several things.
Among them are the "terminal lines" going to your keyboard and display.
What do you mean when you say, "Terminal lines", does it means the input-
output signals?
Before Linux (and before Microsoft and Apple :) there was an OS called
UNIX. It is still around in many flavors. Linux was closely modeled
after UNIX. In the late 60's when UNIX was starting you didn't work
with fancy graphics, only text, and the device with the keyboard
might not have a video screen, but a roll of paper. These devices
(paper printing and video) were called "terminals". The original ones
were known as "teletypes". They were physically plugged into a port
on the computer. Because the ports were used to connect to TeleTYpe
terminals, these ports came to be known as "tty lines". You can probably
still see their legacy in the device directory, try "ls /dev/tty*".
In a graphical environment text based windows typically emulate one of
those old terminals. Thus they have to connect to a "tty line". In
one of your terminal window run the tty command, it will report what
tty line your window is connected to. It is probably /dev/pty<xxx>
or maybe /dev/pts/<xxx>. The "p" in those device names stands for
"pseudo" because they mimic the physical ports with software.
When you login, and/or start a terminal window, you are given ownership
of the /dev/??? terminal line your window is using. When cron starts
one of your jobs it doesn't login and does not get a terminal line.
Thus it has no screen (window) to send output to and no connected
keyboard to get interactive input from.
If you login to a graphical environment many things about the window
manager and system are also setup and entered into your "environment".
Much of this is via shell variables you can see with the "env" command.
An important one is DISPLAY.
I have read the lines generated by the env command. Now, this looks like
there must be some files that are loading the environment similar to the
centralised Windows registry.
========================================================
My lines typically are:
========================================================
ORBIT_SOCKETDIR=/tmp/orbit-root
SSH_AGENT_PID=2799
TERM=xterm
SHELL=/bin/bash
XDG_SESSION_COOKIE=d2950bc30d22ada616a24d3100000009-1348804879.438647-148187592
GTK_RC_FILES=/etc/gtk/gtkrc:/home/user/.gtkrc-1.2-gnome2
WINDOWID=102760451
GNOME_KEYRING_CONTROL=/tmp/keyring-7Brd7u
GTK_MODULES=gail:atk-bridge
USER=root
SSH_AUTH_SOCK=/tmp/keyring-7Brd7u/ssh
SESSION_MANAGER=local/Squeeze:@/tmp/.ICE-unix/2749,unix/Squeeze:/tmp/.ICE-
unix/2749
USERNAME=user
DESKTOP_SESSION=default
MAIL=/var/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/home/user
GDM_KEYBOARD_LAYOUT=us
LANG=en_IN
GNOME_KEYRING_PID=2249
GDM_LANG=en_IN
GDMSESSION=default
HOME=/root
SHLVL=2
LANGUAGE=en_IN:en
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
LOGNAME=root
XDG_DATA_DIRS=/usr/share/gnome:/usr/share/gdm/:/usr/local/share/:/usr/
share/
WINDOWPATH=7
DISPLAY=:0.0
XAUTHORITY=/tmp/libgksu-27pE1G/.Xauthority
COLORTERM=gnome-terminal
_=/usr/bin/env
===========================================================
I am aware that there is no central registry in Linux.
On Linux, lets differentiate programs and processes. A program
is that thing you see on the disk, not loaded into memory, eg. /bin/ls.
A process is a running program. When a process is created it not only
receives the code from the disk program but also some "housekeeping"
information, eg. the identity of who is running this process, what
was the parent of this process, what files are open, etc. It also
receives an "environment", the stuff you see above. The new process
inherits the environment, and the open files, of its parent. Thus,
the child process can write to the same screen (window) as it parent,
and it can read the same stream of keyboard characters.
How do I know more about this, like interpreting the lines of codes
generated by 'env' above?
How do you interpret the entries in the windows registry?
HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices\??\Volume{.....} REG_BINARY 70
2e 34 ...
Basically you don't. Some are fairly obvious (ex. LOGNAME=root),
others may be specific to some application. Some you read about
in a basic linux text (ex. PATH=...) while others may be specific
to an application (ex. SSH_AUTH_SOCKET=...) and you would read the
man pages and/or some text about the application (ssh in this case).
When a program runs from a crontab (gnome-schedule just eases the editing
of your crontab) that program runs "without logging in". It doesn't have
all the environment setup that a login session has. Because of this,
programs run by cron typically are not interactive. Consider that the
person at the keyboard and display when the program runs might not even
be you, or when that 4AM cronjob runs, what is the likelyhood that you
are sitting at your keyboard logged in? Does that mean interactive, or
GUI programs can not be run from cron? No, but it does mean that you
will have to recreate some of your logged-in environment and you may have
to take steps to ensure you are even available.
And in the end, does it mean that if I run a script in Crontab that
passes the precise environment a particular program needs, I could
theoretically make an application interactive?
You could do something like "cronjobcmd < /dev/pts/3 > /dev/pts/3"
and assuming you were logged in, and assuming ONE of your windows
was terminal line pts/3, you might be able to have an interactive
cronjob. But how do you know in advance whether you will be
logged in and using that terminal line?