小编Jus*_*tin的帖子

Htop sorting CPU% column incorrectly

Sometimes when I\'m trying to diagnose what process is hogging all of my laptop\'s resources, I notice that htop will sort the CPU% column incorrectly.

\n\n

Example below:

\n\n

屏幕截图 2018-07-06 10 47 23 am

\n\n

The \xe2\x80\x9cCPU%\xe2\x80\x9d column is highlighted in the header row, so that means its sorting by that column (right?), yet it\xe2\x80\x99s all out of order. It\xe2\x80\x99s clearly not sorting it numerically, and neither is it sorting it lexicographically. I\'m not sure how else it could be trying to sort it.

\n\n …

osx top sort htop cpu-usage

8
推荐指数
1
解决办法
1873
查看次数

查看单独的活动 TTY 的 bash 历史记录

我正在编写一个脚本,该脚本将帮助我们团队的系统管理员监控其他登录用户在其他终端上发生的事情。

我现在遇到的一件事是如何查看已键入的命令。我意识到在用户退出或输入之前不会保存历史记录history -a,但是必须有一种方法来查看当前历史记录中的内容,即使它存储在内存中的某处。

它可能保存在某个地方/proc/${pid_of_users_bash}吗?我试着键入命令呼应的唯一字符串(EG: echo "foobarbaz",然后greping为foob​​arbaz 通过相关联的任何平面文件/proc/PID的目录,但没有运气。

如果有人有不涉及设置PROMPT_COMMAND或设置histappend(像这些)的解决方案,那将不胜感激。

shell command-history tty proc

5
推荐指数
1
解决办法
1977
查看次数

bash 数组 $PIPESTATUS 有问题

我正在编写一个脚本(它将在 OSX 上运行,可能没有别的),它基本上只是解析/var/log/accountpolicy.log*日志以获取身份验证时间/计数。初始命令是通过zgrep执行的sudo,它通过管道传输到awk,执行 awk 脚本。命令运行后,我${PIPESTATUS[@]}用来确定是否有任何失败,如果失败,是哪个部分。

这是当前状态的 awk 脚本:

#! /usr/local/bin/awk -f

BEGIN {
  return_code = 0
  if ( length( username ) == 0 ){
    return_code = 2
    exit return_code
  }

  rows = 0
}
{ 
  if ( $8 != sprintf("\"%s\",", username ) ) next

  rows = rows+1
  print $0
} 
END {
  if ( return_code > 0 ) exit return_code
  if ( rows == 0 ) exit 3
}
Run Code Online (Sandbox Code Playgroud)

awk …

osx bash pipe io-redirection awk

5
推荐指数
1
解决办法
872
查看次数

标签 统计

osx ×2

awk ×1

bash ×1

command-history ×1

cpu-usage ×1

htop ×1

io-redirection ×1

pipe ×1

proc ×1

shell ×1

sort ×1

top ×1

tty ×1