Shell脚本有问题


#!/bin/bash
while [ true ]
do
echo "$(top -b -o +%MEM -n 1 | head -n +8 | tail -n 1 | awk '{ print $12";"$10 }');$(date +'%H:%M:%S')" >> RAM.csv
if [ -z "$1" ]; then 
sleep 1m
else 
sleep "$1"
fi
done

错误输出:日期:额外操作数'%H:%M:%S'这有什么不对吗?

下面是您的脚本的稍微改进的版本:

#!/usr/bin/env bash
# All output is appended to RAM.csv
exec >> RAM.csv
# Do an infinite loop
while :; do
# Get command with most used memory, print it in CSV format, append time
date "+$(ps -eo ucmd -o '%mem' --sort=-%mem h | awk -v OFS=";" '($1=$1);{exit}');%T"
# sleep $1 seconds, if not defined 1m
sleep "${1:-1m}"
done

相关内容

  • 没有找到相关文章

最新更新