Top Command Output is Empty when run from cron

前端 未结 2 1329
萌比男神i
萌比男神i 2021-01-25 06:29

I was trying to redirect the TOP command output in the particular file in every 5 minutes with the below command.

top -b -n 1 > /var/tmp/TOP_USAGE.csv.$(date          


        
相关标签:
2条回答
  • 2021-01-25 07:17

    I met the same problem as you.

    Top command with -b option must be added.Saving top output to variable before we use it.

    the scripts are below

    date >> /tmp/mysql-mem-moniter.log

    MEM=/usr/bin/top -b -n 1 -u mysql

    echo "$MEM" | grep mysql >> /tmp/mysql-mem-moniter.log

    0 讨论(0)
  • 2021-01-25 07:26

    Most likely the environment passed to your script from cron is too minimal. In particular, PATH may not be what you think it is (no profiles are read by scripts started from cron).

    Place PATH=$(/usr/bin/getconf PATH) at the start of your script, then run it with

    /usr/bin/env -i /path/to/script
    

    Once that works without error, it's ready for cron.

    0 讨论(0)
提交回复
热议问题