小编Vee*_*anu的帖子

如何在shell脚本中实现logrotate

测试文件

#!/bin/bash
echo "Hello World"
Run Code Online (Sandbox Code Playgroud)

测试2.sh

#!/bin/bash
while true
do
    sh test.sh >> /script_logs/test.log &
done
Run Code Online (Sandbox Code Playgroud)

我想实现logrotate来控制日志文件的大小,那么如何实现logrotate,如果是上面的情况呢?

scripting bash logrotate

18
推荐指数
2
解决办法
6万
查看次数

shell脚本自行终止的原因可能是什么?

我有像这样的shell脚本

#!/bin/bash
while true;do
   #Code HERE!
   #Pushing Data to DB
   echo "Data to DB"> /root/schip.log 2>&1
done
Run Code Online (Sandbox Code Playgroud)

该脚本不断运行并收集服务器上的信息,然后将数据发送到数据库(时间戳数据库)。我不知道为什么,有时脚本会死掉。在日志中我看不到任何东西。同样,我在Python脚本中看到了。Python 脚本是这样的

import <stuff>
while True:
   #Code HERE
   #Push data to DB
   print "Data to DB"
Run Code Online (Sandbox Code Playgroud)

那么,可能是什么原因造成的呢?如何预防呢?以及如何启用日志(在 python 和 Shell 中)以了解原因?谢谢!

python shell-script

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

使用 supervisord 重定向命令输出

docker -H :4000 events | ./docker_events.py
Run Code Online (Sandbox Code Playgroud)

docker -H :4000 events将连续给出事件,直到我们按下Crtl+C。因此,我pipe将输出输出到我的自定义脚本docker_events.py,该脚本解析返回的输出,docker -H :4000 events然后为其提供自己的输出版本(实际上它会将 json 数据发送到redis!)

我在supervisord .conf下面包含了上面的行

[program:docker_events]
command=docker -H :4000 events | python /root/docker_events.py
autostart=true
autorestart=true
stderr_logfile=/var/log/docker_events.err.log
stdout_logfile=/var/log/docker_events.out.log
Run Code Online (Sandbox Code Playgroud)

但它不能正常工作;我可以看到错误 docker_events.err.log

Usage:  docker events [OPTIONS]

Get real time events from the server
docker: "events" requires 0 arguments.
See 'docker events --help'.
Run Code Online (Sandbox Code Playgroud)

它是|作为论据。那么我可以解决这个问题吗?

supervisord

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

标签 统计

bash ×1

logrotate ×1

python ×1

scripting ×1

shell-script ×1

supervisord ×1