Home > Software engineering >  crontab i have the error TERM environment variable not set
crontab i have the error TERM environment variable not set

Time:12-08

im using top command on shell script, when its executed on crontab i have the error TERM environment variable not set. below my script:

#!/bin/bash

HOST=`hostname`

echo "---------------------------------------------------------------------------"
echo "Check cpu load & Memory with top on $HOST at $(date  %d/%m/%y-%H:%M:%S)"
echo "---------------------------------------------------------------------------"
echo ""
/usr/bin/top -n 1
echo ""
echo ""
echo "------check zombie process---"
/usr/bin/top -n 1 |grep zombie
echo "-----------------------------"

result after crontab script is executed

00 14 * * * /home/doug/topcommand.sh > /home/doug/check_`hostname`_`date  \%Y\%m\%d`.log   2>&1

TERM environment variable not set.

im expecting a top command result

CodePudding user response:

You need to run top is batch mode for it to work in a crontab.

Use /usr/bin/top -b -n 1

It may also be useful to specify the output width you want with -w, e.g., -w 512 to get very long lines of output.

Ref: https://man7.org/linux/man-pages/man1/top.1.html

  • Related