Miroslav Lachman wrote on 11/22/2015 12:03:> Michael B. Eichorn wrote on 11/21/2015 21:42: >> On Sat, 2015-11-21 at 13:31 +0100, Miroslav Lachman wrote: >>> I noticed some weird behavior of "su" command in shell scripts >>> running >>> from cron after upgrade from FreeBSD 8.4 to 10.2. >>> >>> If I have this in script >>> >>> su -m www -c 'ls -l' >>> >>> then I get "TERM: Undefined variable" on the stderr if this script is >>> run from cron. >>> It works fine on FreeBSD 8.4 >>> >>> Is it intentional behavior? >>> >>> Miroslav Lachman >> >> I cannot reproduce your problem. I used the following script: >> >> #!/bin/sh >> >> echo "BEGIN TEST" >> echo $TERM >> >> su -m www -c 'ls -l' >> >> echo $TERM >> echo "END TEST" >> >> crontab is: >> * * * * * /root/test.sh >> >> and the result is: >> >> BEGIN TEST >> >> total 520765 >> -rw-r--r-- 1 root wheel 724002816 Aug 12 11:45 FreeBSD-10.2- >> RELEASE-amd64-disc1.iso >> -rwxr-xr-x 1 root wheel 90 Nov 21 15:33 test.sh >> >> END TEST >> >> # freebsd-version >> 10.2-RELEASE-p7 >> > > It's a strange. I tried it on another machine which was installed as > 10.1 and upgraded to 10.2-p5 - and I got Undefined variable again: > > BEGIN TEST > > TERM: Undefined variable. > total 8984 > drwxr-xr-x 2 root wheel 1536 Aug 12 13:48 bin > -rw------- 1 root wheel 9134080 Nov 22 00:06 dns-terror.core > -rw-r--r-- 1 root wheel 836 Nov 5 10:39 extensions.ini > drwxr-xr-x 3 root wheel 512 Jul 29 17:49 settings > drwxr-xr-x 8 root wheel 512 Aug 9 04:59 settings_atago > drwxr-xr-x 2 root wheel 512 Aug 9 03:12 skel_devel > -rwxr--r-- 1 root wheel 90 Nov 22 11:52 term_test.sh > > END TEST > > Miroslav LachmanThe only workaround I found is adding export TERM="" at the top of the script.
Hi, On Sun, 22 Nov 2015 14:04:25 +0100 Miroslav Lachman <000.fbsd at quip.cz> wrote:> > > > Miroslav Lachman > > The only workaround I found is adding > export TERM="" > at the top of the script. >this is a bit strange. TERM should be always define to tell the applications the capabilities of your terminal. When X is running, it is normally set to xterm, if nothing is available - or you do not know what is available - set it to vt100. Of course, the best would be to find out why it is not set on your machine. Erich
Erich Dollansky wrote on 11/23/2015 00:31:> Hi, > > On Sun, 22 Nov 2015 14:04:25 +0100 > Miroslav Lachman <000.fbsd at quip.cz> wrote: > >>> >>> Miroslav Lachman >> >> The only workaround I found is adding >> export TERM="" >> at the top of the script. >> > this is a bit strange. TERM should be always define to tell the > applications the capabilities of your terminal. When X is running, it > is normally set to xterm, if nothing is available - or you do not know > what is available - set it to vt100. > > Of course, the best would be to find out why it is not set on your > machine.TERM is not set or is empty if script runs from crontab. I think this is normal. Michael's test didn't print value of $TERM too, but his su didn't complained about "Undefined variable". If I run this script in ssh session it prints "screen", because I am using screen. Miroslav Lachman