F.Eliasius
F.Eliasius

Reputation: 21

crontab i have the error TERM environment variable not set

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

Upvotes: 0

Views: 71

Answers (1)

joanis
joanis

Reputation: 12221

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

Upvotes: 1

Related Questions