我想制作一个shell脚本,它将有效地从输出到控制台的sterr和stin中获取最后n行.我有一个屏幕会话运行一个进程,如果它通过hacky无限循环崩溃将重新启动它:
#!/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
Run Code Online (Sandbox Code Playgroud)
我需要的是第7行代码从stderr和stdin中获取最后10行左右并将它们附加到日志文件中
我有一个非常简单的脚本,它分配内存,dels唯一引用一个相当大的对象,一直打印heapy和pidstat报告.在运行脚本之后,heapy告诉我,当pidstat告诉我相反时,不应该使用太多内存:
from guppy import hpy
import time
import sys
import os
'''
1) print heapy and pidstat report after starting and before actually doing any work
2) allocate some memory in a simple 2d array
3) print heapy and pidstat report
4) del the d2 array (attempt at garbage collection)
5) print heapy and pidstat report
6) sleep so pidstat can continue to be run to check on memory
'''
def pidstat(msg):
print '===============================' …Run Code Online (Sandbox Code Playgroud) 我编写了一个简单的服务器来扩展SimpleHTTPRequestHandler
如果我在没有向服务器发出任何请求的情况下启动和停止它,我可以开始备份同一个端口,没有任何问题.
启动时,netstat看起来像这样:
sam@hersheezy:server$ sudo netstat -na --program | grep 8001 tcp 0 0 0.0.0.0:8001 0.0.0.0:* LISTEN 23392/python
发出请求后,netstat看起来像这样(即使请求完成后):
sam@hersheezy:server$ sudo netstat -na --program | grep 8001 tcp 0 0 0.0.0.0:8001 0.0.0.0:* LISTEN 23392/python tcp 0 0 127.0.0.1:8001 127.0.0.1:48659 TIME_WAIT -
然后,我使用Cc杀死服务器,netstat看起来像这样(此时我无法重启服务器,因为端口已经在使用):
sudo netstat -na --program | grep 8001 tcp 0 0 127.0.0.1:8001 127.0.0.1:48674 TIME_WAIT -
我显然没有正确地关闭一些东西.我发送回复的代码如下所示:
"""
reply is an object that can be json encoded that is written with a response code 200
"""
def send_provider_reply(self, replyobj): …Run Code Online (Sandbox Code Playgroud) 当试图在Ubuntu 12.1机器上创建我的测试项目时:
adb install bin/opine_test-debug.apk
adb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)
所以我去安装lib64ncurses(我的确运行64位操作系统):
sudo apt-get install lib64ncurses5
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information …Run Code Online (Sandbox Code Playgroud) python ×2
python-2.7 ×2
adb ×1
android ×1
bash ×1
gnu-screen ×1
http ×1
logging ×1
memory-leaks ×1
shell ×1
time-wait ×1
ubuntu ×1