65

I have a file.sh with this, when run show : TERM environment variable not set.

smbmount //172.16.44.9/APPS/Interfas/HERRAM/sc5 /mnt/siscont5 -o 
iocharset=utf8,username=backup,password=backup2011,r

if [ -f /mnt/siscont5/HER.TXT ]; then
    echo "No puedo actualizar ahora"
    umount /mnt/siscont5
else 
    if [ ! -f /home/emni/siscont5/S5.TXT ]; then
        echo "Puedo actualizar... "
        touch /home/emni/siscont5/HER.TXT
        touch /mnt/siscont5/SC5.TXT
        mv -f /home/emni/siscont5/CCORPOSD.DBF /mnt/siscont5
        mv -f /home/emni/siscont5/CCTRASD.DBF /mnt/siscont5
        rm /mnt/siscont5/SC5.TXT
        rm /home/emni/siscont5/HER.TXT
        echo "La actualizacion ha sido realizada..."
    else
        echo "No puedo actualizar ahora: Interfaz exportando..."
    fi
fi
umount /mnt/siscont5
echo "/mnt/siscont5 desmontada..."
4

6 回答 6

98

You can see if it's really not set. Run the command set | grep TERM.

If not, you can set it like that: export TERM=xterm

于 2013-04-27T13:08:52.523 回答
61

Using a terminal command i.e. "clear", in a script called from cron (no terminal) will trigger this error message. In your particular script, the smbmount command expects a terminal in which case the work-arounds above are appropriate.

于 2015-11-12T19:42:28.857 回答
6

You've answered the question with this statement:

Cron calls this .sh every 2 minutes

Cron does not run in a terminal, so why would you expect one to be set?

The most common reason for getting this error message is because the script attempts to source the user's .profile which does not check that it's running in a terminal before doing something tty related. Workarounds include using a shebang line like:

#!/bin/bash -p

Which causes the sourcing of system-level profile scripts which (one hopes) does not attempt to do anything too silly and will have guards around code that depends on being run from a terminal.

If this is the entirety of the script, then the TERM error is coming from something other than the plain content of the script.

于 2013-04-27T13:28:15.597 回答
0

SOLVED: On Debian 10 by adding "EXPORT TERM=xterm" on the Script executed by CRONTAB (root) but executed as www-data.

$ crontab -e

*/15 * * * * /bin/su - www-data -s /bin/bash -c '/usr/local/bin/todos.sh'

FILE=/usr/local/bin/todos.sh

#!/bin/bash -p
export TERM=xterm && cd /var/www/dokuwiki/data/pages && clear && grep -r -h '|(TO-DO)' > /var/www/todos.txt && chmod 664 /var/www/todos.txt && chown www-data:www-data /var/www/todos.txt
于 2019-10-25T15:47:40.553 回答
0

If you are using the Docker PowerShell image set the environment variable for the terminal like this with the -e flag

docker run -i -e "TERM=xterm" mcr.microsoft.com/powershell
于 2021-05-06T20:49:29.650 回答
0

You can replace :

export TERM=xterm

with :

export TERM=linux

It works even in kernel with virgin system.

于 2022-02-22T13:57:15.533 回答