Script running from terminal and doesn't from cron

34 views
Skip to first unread message

Mikhail Romanenko

unread,
Nov 30, 2001, 6:39:29 AM11/30/01
to
Few of my bash scripts running without problem when are executed from
terminal but are not when executed from cron. In one of the scripts I found a
comand string that behave this way. It is:

"/usr/bin/strace /usr/sbin/iptraf -i ppp0 -B -L /var/log/iptraf/ip_traffic-bg.log"

I executed it from terminal and cron. Here is "diff -u" of outputs (iptraf.cron
executed from cron, iptraf.term from terminal):

--- iptraf.cron Fri Nov 30 15:02:20 2001
+++ iptraf.term Fri Nov 30 15:03:32 2001
@@ -1,4 +1,4 @@
-execve("/usr/sbin/iptraf", ["/usr/sbin/iptraf", "-i", "ppp0", "-B", "-L",
"/var/log/iptraf/ip_traffic-bg.log"], [/* 7 vars */]) = 0
+execve("/usr/sbin/iptraf", ["/usr/sbin/iptraf", "-i", "ppp0", "-B", "-L",
"/var/log/iptraf/ip_traffic-bg.log"], [/* 18 vars */]) = 0
uname({sys="Linux", node="lee", ...}) = 0
brk(0) = 0x8068b00
open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory)
@@ -33,8 +33,8 @@
munmap(0x40016000, 29604) = 0
getuid32() = 0
open("/var/run/iptraf/iptraf.tag", O_RDONLY) = -1 ENOENT (No such file or
directory)
-write(2, "Your TERM variable is not set.\n", 31Your TERM variable is not set.
-) = 31
-write(2, "Please set it to an appropriate "..., 39Please set it to an appropriate
value.-) = 39
-_exit(1) = ?
\ No newline at end of file
+open("/var/lib/iptraf/iptraf.cfg", O_RDONLY) = 3
+read(3, "\317\232\7@\17\0\0\0\20\16\0\0\0\0\0\0\0\0\0\0", 20) = 20
+close(3) = 0
+fork() = 18214
+_exit(0) = ?

Software used:
Linux Debian Unstable
kernel 2.4.14
libc6 2.2.4
bash 2.05a
iptraf 2.4.0

Before upgrading bash I haven't seen such problems.

Can anybody help me to understad what's is wrong.

Thank you, Mikhail.


-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Glynn Clements

unread,
Nov 30, 2001, 10:39:59 AM11/30/01
to

Joseph Spainhour wrote:

> looks like your environment is not setup correctly under cron.
> You might want to have a look at /etc/profile, or just add env entries
> to your script.
>
> ->-write(2, "Your TERM variable is not set.\n", 31Your TERM variable is not set.
> -> -) = 31
>
> This line shows that cron does not have a TERM variable. Try putting
>
> TERM=linux;export TERM
>
> in your script.

TERM *should* be unset for cron jobs, as they aren't associated with a
terminal.

If a program expects TERM to be set, that normally indicates that it
is meant to be run interactively (there are exceptions; e.g. some
versions of lynx insist upon TERM being set, even for "lynx -dump").

If you think that iptraf can be run from a script, try setting
"TERM=dumb".

--
Glynn Clements <glynn.c...@virgin.net>

Mikhail Romanenko

unread,
Dec 1, 2001, 5:40:01 AM12/1/01
to
Thank you, guys for the help.
The scripts have begun to work fine after I add "TERM=linux;export TERM" into them.
Adding string "echo $TERM" into scripts before correction of TERM revealed that
TERM==dumb if script was executed from cron.

To be honest, I don't understand why they didn't work before and work now, I have a
bunch of scripts and all of them work fine but two. Perhaps it has something to do with
that these two log heavily. Couldn't anybody give a hint where to seek for explanation.

Thank you, Mikhail.

30.11.2001 20:24:05, Joseph Spainhour <spai...@coastalnet.com> wrote:

>Hi Mikhail,


>
> looks like your environment is not setup correctly under cron.
>You might want to have a look at /etc/profile, or just add env entries
>to your script.
>
>->-write(2, "Your TERM variable is not set.\n", 31Your TERM variable is not set.
>-> -) = 31
>
>This line shows that cron does not have a TERM variable. Try putting
>
>TERM=linux;export TERM
>
>in your script.
>

>Joseph

Glynn Clements

unread,
Dec 1, 2001, 11:37:51 AM12/1/01
to

Mikhail Romanenko wrote:

> Thank you, guys for the help.

> The scripts have begun to work fine after I add "TERM=linux;export
> TERM" into them. Adding string "echo $TERM" into scripts before
> correction of TERM revealed that TERM==dumb if script was executed
> from cron.
>
> To be honest, I don't understand why they didn't work before and
> work now, I have a bunch of scripts and all of them work fine but
> two. Perhaps it has something to do with that these two log heavily.
> Couldn't anybody give a hint where to seek for explanation.

$TERM is used by the termcap and terminfo libraries. These libraries
allow programs to determine the capabilities of the terminal, and to
obtain the control sequences which are used for operations such as
cursor positioning, setting text properties (colour, bold, blink) etc.

The main user of the termcap/terminfo libraries is the curses (aka
ncurses) library; on some systems, the termcap/terminfo functionality
is actually part of the curses library, rather than being separate
libraries.

You can get more information from the ncurses manpages, starting with
ncurses(3).

Your problem seems to be that one or more of the programs which is
used by the scripts use one of these libraries. Normally this would
indicate that the program cannot be scripted. However, some programs
which are normally used interactively can also be used
non-interactively. Sometimes such programs (e.g. lynx) always
initialise curses, even when they don't need it (i.e. "lynx -dump").
Initialisation of the curses library will fail if TERM is unset, or if
it refers to a terminal which doesn't support cursor positioning (e.g.
"dumb").

--
Glynn Clements <glynn.c...@virgin.net>

Reply all
Reply to author
Forward
0 new messages