Linux 未设置 TERM 环境变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16242025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TERM environment variable not set
提问by meyquel
I have a file.sh with this, when run show : TERM environment variable not set.
我有一个 file.sh,运行时显示:未设置 TERM 环境变量。
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..."
采纳答案by cpr4t3s
You can see if it's really not set. Run the command set | grep TERM
.
你可以看看它是否真的没有设置。运行命令set | grep TERM
。
If not, you can set it like that:
export TERM=xterm
如果没有,你可以这样设置:
export TERM=xterm
回答by Petesh
You've answered the question with this statement:
您已经用以下声明回答了这个问题:
Cron calls this
.sh
every 2 minutes
Cron
.sh
每 2 分钟调用一次
Cron does not run in a terminal, so why would you expect one to be set?
Cron 不在终端中运行,那么您为什么希望设置一个呢?
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:
收到此错误消息的最常见原因是因为脚本尝试获取用户的源,.profile
而在执行与 tty 相关的操作之前,该脚本并未检查它是否在终端中运行。解决方法包括使用 shebang 行,如:
#!/bin/bash -p
#!/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 otherthan the plain content of the script.
如果这是整个脚本,则TERM
错误来自脚本的纯内容以外的其他内容。
回答by Josiah DeWitt
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.
在从 cron(无终端)调用的脚本中使用终端命令即“清除”将触发此错误消息。在您的特定脚本中, smbmount 命令需要一个终端,在这种情况下,上述变通方法是合适的。
回答by davidjimenez75
SOLVED: On Debian 10 by adding "EXPORT TERM=xterm" on the Script executed by CRONTAB (root) but executed as www-data.
已解决:在 Debian 10 上,通过在由 CRONTAB(root)执行但作为 www-data 执行的脚本上添加“EXPORT TERM=xterm”。
$ crontab -e
$ crontab -e
*/15 * * * * /bin/su - www-data -s /bin/bash -c '/usr/local/bin/todos.sh'
FILE=/usr/local/bin/todos.sh
文件=/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