我想制作一个shell脚本,它将有效地从输出到控制台的sterr和stin中获取最后的n行。我有一个屏幕会话运行一个进程,如果它通过一个奇怪的无限循环崩溃将重新启动:
原文链接:/bash/387617.html#!/bin/bash #This script will be started in a screen session counter=0 while [ $counter -lt 10 ]; do ./run_some_process; last_output=#GRAB PREVIoUS OUTPUT FROM CONSOLE HERE AND LOG TO FILE echo -e "$last_output" >> mylog.txt; sleep 5; #sleep for a few seconds before restarting done