meyquel
meyquel

Reputation: 2214

TERM environment variable not set

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..."

Upvotes: 80

Views: 227491

Answers (6)

Akram BENGHANEM
Akram BENGHANEM

Reputation: 139

You can replace :

export TERM=xterm

with :

export TERM=linux

It works even in kernel with virgin system.

Upvotes: 4

Evyatar Saias
Evyatar Saias

Reputation: 776

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

Upvotes: 0

davidjimenez75
davidjimenez75

Reputation: 45

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

Upvotes: 0

Josiah DeWitt
Josiah DeWitt

Reputation: 1802

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.

Upvotes: 82

cpr4t3s
cpr4t3s

Reputation: 1445

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

Upvotes: 115

Anya Shenanigans
Anya Shenanigans

Reputation: 94614

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.

Upvotes: 6

Related Questions