useful-scripts

oldratleeApache-2.0更新放缓

一套面向开发者的 Shell/Java 日常脚本合集,能快速排查 Java 线程占用、重复类等常见问题,省去手动敲命令的麻烦。

🐌 useful scripts for making developer's everyday life easier and happier, involved java, shell etc.

v3.0.0-Alpha发布于 2024-04-15 12:07 UTC7,515star2,786fork同步于 2026-11-10 11:32 UTC

怎么上手

README 里没有找到可直接复制的安装命令

README 里没有找到可直接复制的安装命令,请到 README 或官方文档查看安装方式。

硬件要求

README 没有说明硬件要求。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

这个项目的说明还在生成中,先参考下面「最近发版」和 README。

最近发版

5 个版本v3.0.0-Alpha
  1. v3.0.0-Alpha🐌 v3.0.0-Alpha: a WIP/cleanup release最新正式版2024-04-15 · 2024-04-15 12:07 UTC

    [!NOTE] This is a WIP/cleanup release for upgrading version to 3.x

    • remove legacy bin 🚮
    • rename dir test-cases to test 🆙

    It's time to say goodbye, my friend

    It's been a long day without you my friend And I'll tell you all about it when I see you again We've come a long way from where we began Oh I'll tell you all about it when I see you again


    Have Fun! 💕 2024-04-15

  2. v2.5.4🐌 v2.5.4 🍬🎰2024-04-12 · 2024-04-12 05:47 UTC
    查看更新说明

    ☘️ Features

    • [c]: ensure using command on PATH, and check the command existence on PATH 👣
    • [coat/taoc]: add --help/--version options 🚩

    🍬 Improvements

    • [find-in-jars]: add IFS= for read, more robust 💪
      • file paths may contain leading spaces
    • [show-busy-java-threads]:
      • improve separator blank line output 💅 fix wrong blank line logic
      • extract timestamp var to avoid inconsistency ⌚️
    • unify error message format and refactor related functions ℹ️
      • keep usage function simple
      • use -s/-h option for optional argument of die function
    • use ${var##*/} instead of basename to assign PROG var 🎛️
      • faster, no subprocess fork
    • use command realpath instead of function portableReadLink 🔗
      • faster and without losing portability
    • use bash builtin type -P instead of which command, faster 🐚

    🛠️ Refactor

    • [show-busy-java-threads]: rename global var USER -> WHOAMI 👤
    • [uq]: use exponential operation instead of multiplication to calculate size 🧮
    • [c]: rename functions 🔡
    • use Shell Arithmetic comparison instead of Conditional Expressions 🔢
    • use = instead of == in Conditional Expressions
    • use ||/&& instead of one branch/one line if 🎰
    • inline colorPrint function if only one caller
    • variable related refactors:
      • extract UNAME var 🔠
      • rename var, use COLOR_INDEX instead of COUNT
      • remove declare keyword for global vars, more consistent
      • use upper-case var name for global readonly vars
      • unset temp global vars after use
      • remove unnecessary {} when use var
      • remove local nl=$'\n' declaration if only one usage
    • small code cleanup
      • remove unnecessary file descriptor number 1 in redirections ➡️
      • remove section comments for simple section
      • improve/fix/add code comments

    📚 Documentation

    • update manual pages links to manned.org 📚
    • use shellcheck item doc link instead of prolixity comments ✨

    🚜 Build/CI

    • upgrade GitHub actions; add dependabot.yml 🤖
    • upgrade shunit2 lib

    Have Fun! 💕 2024-04-12

  3. v2.5.3🐌 v2.5.3 ☕️2024-02-18 · 2024-02-18 05:05 UTC
    查看更新说明

    🍬 Improvements

    • [show-busy-java-threads] support Java21 🆕 ☕️
      • missing stack on Java21, because Java21 changed the format of stack title line (issue #120 submmited by @jianyun)
    • [show-busy-java-threads] improve separator blank line output format 💅

    Have Fun! 💕
    2024-02-18

  4. v2.5.2🐌 v2.5.2 🌗🐚🐈2024-01-24 · 2024-01-24 18:05 UTC
    查看更新说明

    🐞 BugFix

    • coat/taoc: missing last line if there’s no newline at the end of the file 🌗 🙀
    • xpl: wrong exit code when file not existed or open file failure 🔢

    🛠️ Improvements/Refactor

    • find bash with /usr/bin/env in shebang (by @hyperupcall in #119) 🐚
    • coat/taoc: 🐈
      • remove pipe when naked cat(more straightforward and faster) 😸
      • extract colorLines function 🌈
    • a2l: merge function colorPrint into rotateColorPrint 🛠️
    • improve readability
      • remove var interpolation in printf format if possible
      • rename vars, e.g. message -> content, normal -> color_reset 👓
      • use \e instead of \033
      • improve comments for -t check
    • simplify var usage
      • remove unnecessary {} when use var
      • remove quote of values in simple assignment

    🚜 Build/CI

    • upgrade shunit2 lib

    Have Fun! 💕 2024-01-25

  5. v2.5.1🐌 v2.5.1 🐞🚞🕵️2023-12-05 · 2023-12-05 05:39 UTC
    查看更新说明

    🐞 BugFix

    • c: wrong exit code with -q option 🐞

    🛠️ Improvements/Refactor

    • use ${array[@]:-}/${array[@]:+} to simplify codes 🚞
    • use file descriptor number instead of /dev/std* (issue #114 summitted by @wushengde)
    • console-text-color-themes.sh, improve robustness/portability:
      • use BASH_SOURCE array to detect whether this script is sourced or not 🕵️
      • use printf 💪 instead of echo
      • use if instead of &&
      • remove global var declare if possible

    📚 Documentation

    • add more resources of bash 📚

    Have Fun! 💕
    2023-12-05

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    🐌 useful scripts for making developer's everyday life easier and happier, involved java, shell etc.

    👉 平时有用的手动操作做成脚本,以便捷地使用,让开发的日常生活更轻松些。 💕

    欢迎 👏 💖

    本仓库的脚本(如Java相关脚本)在阿里等公司(如随身云,见awesome-scripts仓库说明)的线上生产环境部署使用。

    如果你的公司有部署使用,欢迎使用通过 Issue:who's using | 用户反馈收集 告知,方便互相交流反馈~ 💗



    🔰 快速下载&使用

    source <(curl -fsSL https://raw.githubusercontent.com/oldratlee/useful-scripts/release-3.x/test/self-installer.sh)
    

    更多下载&使用方式,参见下载使用。

    📚 使用文档

    ☕ Java相关脚本

    1. show-busy-java-threads
      用于快速排查Java的CPU性能问题(top us值过高),自动查出运行的Java进程中消耗CPU多的线程,并打印出其线程栈,从而确定导致性能问题的方法调用。
    2. show-duplicate-java-classes
      找出jar文件和class目录中的重复类。用于排查Java类冲突问题。
    3. find-in-jars
      在目录下所有jar文件里,查找类或资源文件。

    🐚 Shell相关脚本

    Shell使用加强:

    1. c
      原样命令行输出,并拷贝标准输出到系统剪贴板,省去CTRL+C操作,优化命令行与其它应用之间的操作流。
    2. coat and taoc
      彩色cat/tac出文件行,方便人眼区分不同的行。
    3. a2l
      按行彩色输出参数,方便人眼查看。
    4. uq
      不重排序输入完成整个输入行的去重。相比系统的uniq命令加强的是可以跨行去重,不需要排序输入。
    5. ap and rp
      批量转换文件路径为绝对路径/相对路径,会自动跟踪链接并规范化路径。
    6. cp-into-docker-run
      一个Docker使用的便利脚本。拷贝本机的执行文件到指定的docker container中并在docker container中执行。
    7. tcp-connection-state-counter
      统计各个TCP连接状态的个数。用于方便排查系统连接负荷问题。
    8. xpl and xpf
      在命令行中快速完成 在文件浏览器中 打开/选中 指定的文件或文件夹的操作,优化命令行与其它应用之间的操作流。

    Shell开发/测试加强:

    1. echo-args
      输出脚本收到的参数,在控制台运行时,把参数值括起的括号显示成 红色,方便人眼查看。用于调试脚本参数输入。
    2. console-text-color-themes.sh
      显示Terminator的全部文字彩色组合的效果及其打印方式,用于开发Shell的彩色输出。
    3. parseOpts.sh
      命令行选项解析库,加强支持选项有多个值(即数组)。

    🎓 Developer Guide

    为用户提供有用的功能,当然是这个库的首要的价值体现和存在理由。

    但作为一个开源项目,每个人都可以看到源码实现,这个库或许能做得更多。

    🎯 面向开发者的目标

    • 将Shell/Bash作为线上生产环境使用的专业编程语言。
    • 期望体现Shell/Bash脚本 生产环境级的严谨开发方式与最佳实践,进而有可能示例与改善在生产环境中Shell脚本的质量状况。

    PS:

    • 虽然上面是自己期望的目标,但自己在Shell语言上一定会有很多理解和使用上的问题、在这些实现脚本中也会很多需要的改进,可以一起学习、讨论与实践~ 💕
    • 这个库中脚本的实现也有使用Python。
    关于Shell脚本

    命令行(CLI)几乎是每个程序员每天都在使用的工具。相比图形界面工具(GUI),命令行有着自己不可替代的便利性和优越性。

    命令行里写出来其实就是Shell脚本,可以说每个开发者会写Shell脚本(或多或少)。在生产环境的功能实现中,也常会看到Shell脚本(虽然不如主流语言那么常见)。

    可能正因为上面所说的Shell脚本的便利性和大众性:

    • Shell脚本有不少是顺手实现的(包括生产环境用的Shell脚本);
    • Shell脚本的实现常常可能质量不高,会引发线上严重的故障。

    🚦 开发约定

    在这个库中的Shell脚本:

    • 统一使用Bash 3.2+;
    • 面向生产环境,尽可能使用严谨安全的开发方式。

    Shell用Bash的原因是:

    • 目前仍然是主流的Shell,并且在不同环境基本上都缺省部署了。
    • 在Google的Shell风格指南中,明确说到了:Bash是唯一被允许执行的shell脚本语言。
    • 统一用Bash,可以避免不同Shell之间差异所带来的风险与没有收益的复杂性。
      • 有大量的Shell实现,sh、bash、zsh、fish、csh、tcsh、ksh、ash、dash……
      • 不同的Shell有各种差异,深坑勿入。
    • 个人系统学习过的是Bash,比较理解熟悉。

    PS: 虽然交互Shell个人已经使用Zsh + oh-my-zsh,但在严谨的Shell脚本开发时还是使用Bash。

    📚 Shell学习与开发的资料

    更多资料参见 子文档。