判断目录/tmp/jstack是否存在,不存在则新建一个目录,若存在则删除目录下所有内容-《shell脚本》

admin 2025-11-06 14:31:02 系统网络 来源:ZONE.CI 全球网 0 阅读模式

    每隔 1 小时打印 inceptor server 的 jstack 信息,并以 jstack_${当前时间} 命名文件,每当目录下超过 10 个文件后,删除最旧的文件

    1. #!/bin/bash
    2. DIRPATH='/tmp/jstack'
    3. CURRENT_TIME=$(date +'%F'-'%H:%M:%S')
    4. if [ ! -d "$DIRPATH" ];then
    5. mkdir "$DIRPATH"
    6. else
    7. rm -rf "$DIRPATH"/*
    8. fi
    9. cd "$DIRPATH"
    10. while true
    11. do
    12. sleep 3600
    13. # 这里需要将inceptor改后自己的java进程名称
    14. pid=$(ps -ef | grep 'inceptor' | grep -v grep | awk '{print $2}')
    15. jstack $pid >> "jstack_${CURRENT_TIME}"
    16. dir_count=$(ls | wc -l)
    17. if [ "$dir_count" -gt 10 ];then
    18. rm -f $(ls -tr | head -1)
    19. fi
    20. done
    01-shell脚本介绍-《shell脚本》 系统网络

    01-shell脚本介绍-《shell脚本》

    一、shell脚本是什么二、为什么要学shell,而不是其他计算机语言三、学习这门课程的优势四、学了能干什么五、学习什么内容六、学习的技巧七、成长路径八、学习环
    评论:0   参与:  11