电子邮件 – 以cron缩小的最高输出

我正在尝试通过cron发送电子邮件,以了解哪些进程正在占用我的服务器.它工作正常,但产生的电子邮件太窄,我需要了解更多有关该过程.

这是我正在使用的脚本(从这里偷走它:http://www.inmotionhosting.com/support/website/server-usage/create-server-load-monitoring-bash-script):

#!/bin/bash
trigger=10.00
load=`cat /proc/loadavg | awk '{print $1}'`
response=`echo | awk -v T=$trigger -v L=$load 'BEGIN{if ( L > T){ print "greater"}}'`

if [[ $response = "greater" ]]
then
top -cSbn 1 | head -14 | tail -8 | mail -s"High load on server - [ $load ]" myemail@domain.com
fi

生成的电子邮件类似于:

PID USER      PR  NI  VIRT  RES  SHR S %cpu %MEM    TIME+  COMMAND

 810809 root      20   0 20700  13m 3032 R   50  0.0   0:00.40 /prod/process-nam
 810802 root      20   0 20700  13m 3032 R   48  0.0   0:00.39 /prod/process-nam
 810808 root      20   0 20708  13m 3032 S   48  0.0   0:00.35 /prod/process-nam
 810803 root      20   0 20708  13m 3032 S   46  0.0   0:00.39 /prod/process-nam
 810810 root      20   0 20168  13m 3028 R   46  0.0   0:00.33 /prod/process-nam
 318723 www-data  20   0  146m 131m 3320 R   45  0.4  67:27.96 /home/server/pr
 810800 root      20   0 20704  13m 3032 S   45  0.0   0:00.39 /prod/process-nam

如您所见,整个路径都缺失了.
但是,如果我从bash运行脚本,它可以工作,发送足够广泛的电子邮件.

这是一个ncurses问题吗?管邮件问题?

谢谢!

使用-w开关进行顶部.
-w  :Output-width-override as:  -w [ number ]
        In  'Batch'  mode,when  used without an argument top
        will format output using the COLUMNS= and LInes= envi‐
        ronment  variables,if set.  Otherwise,width will be
        fixed at the maximum 512 columns.  With  an  argument,output width can be decreased or increased (up to 512)
        but the number of rows is considered unlimited.

        In normal display mode,when used without an  argument
        top  will  attempt to format output using the COLUMNS=
        and LInes= environment variables,if  set.   With  an
        argument,output  width  can  only  be decreased,not
        increased.  Whether using environment variables or  an
        argument with -w,when not in 'Batch' mode actual ter‐
        minal dimensions can never be exceeded.

        Note: Without the use  of  this  command-line  option,output  width is always based on the terminal at which
        top was invoked whether or not in 'Batch' mode.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...