• 10-11 周三 shell xargs tr curl 做大事情


     最近发现,shell的小工具非常的强大,简单记录下

    tr命令

    • -d 删除字符串1中所有输入字符。
    • -s 删除所有重复出现字符序列,只保留第一个;即将重复出现字符串压缩为一个字符串

    -d 用于删除查询到的字符串中的空格。

    [test3@NH-DC-NM134-C05-YW-HPC-27 bin]$ cat extract 
    #!/bin/bash
    # 从easybuild配置文件中提取指定键的值
    
    cat /home/test3/.config/easybuild/config.cfg | grep $1 | awk -F "=" '{print $2}' | tr -d " "
    
    • 1
    • 2
    • 3
    • 4
    • 5

    xargs

    curl命令 发起多个POST请求

    发起POST请求,拼接到URL中

    cat images | xargs -I {} -P 3 curl http://10.101.14.36:48001/api/fast-build/task/check-image?image_name={} -X POST -d ‘’

    JSON请求,请求体放在文件中

    find ./ -name raw_json | xargs -p -n1 -li curl -X POST -H “Content-Type: application/json” -d @raw_json http://10.101.14.36:48001/api/fast-build/task/build-image

     其中raw_json内容如下:

    {"webSSHSecret": "j7yC3VEVGFAJIRmnel+XVA==", "jupyterLabSecret": "qkrhxQmWOe5kvpJpplvTuQ==", "task_data": {"task_name": "10.101.12.129-lf99fl@zhejianglab.com-1694483700", "target_image_name": "10.101.12.129/lf99fl-zhejianglab.com/lftestbuild-test:1", "callback_url": "http://pre.alkaidos.cn/api/app/dros-ic-platform/harbor/image/callback"}, "dockerfile_json": {"base_image": "10.101.12.129/base/centos:8-test", "maintainer": "1676883790847406082", "image_installer_config": {"python_env": {"present": "", "update": true, "target": "Python-3.7.14.tgz", "install_loc": "/usr/local/dros/python"}, "pip_installer_config": {"installer_name": "pip", "install": {"present": "", "update": true, "target": "get-pip.py", "install_loc": ""}, "source": {"installer_name": "", "type": "ali", "file_name": "pip.conf"}, "software_list": [], "delimiter": "", "python_version": []}, "package_manager_installer_config": {"installer_name": "yum", "install": {"present": "4.4.2", "update": false, "target": "", "install_loc": ""}, "source": {"installer_name": "", "type": "", "file_name": ""}, "software_list": [], "delimiter": "", "python_version": []}, "conda_installer_config": {"installer_name": "conda", "install": {"present": "", "update": true, "target": "Anaconda3-5.3.1-Linux-x86_64.sh", "install_loc": ""}, "source": {"installer_name": "", "type": "qinghua", "file_name": ".condarc"}, "software_list": [], "delimiter": "", "python_version": []}, "webSSHSecret": "", "jupyterLabSecret": ""}}}
    
    • 1

    多进程触发下载

    [test3@NH-DC-NM134-C05-YW-HPC-27 bin]$ cat downdep 
    #!/bin/bash
    #$1 为将待下载的依赖列表所在的文件名,使用eb -Dr *.eb >dep生成
    count=`cat $1 | grep "\[ \]" | wc -l`
    
    cat $1 | grep "\[ \]" | cut -d "(" -f 1 | awk -F "/" '{print $NF}' |xargs -I file -P "${count}" sh -c "eb --fetch file" 2 > down.error
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
  • 相关阅读:
    Python【查重】
    星环科技重磅推出数据要素流通平台Transwarp Navier,助力企业实现隐私保护下的数据安全流通与协作
    Navicat 查询创建工具 | 使用聚合输出字段-Part 4
    FPS游戏之漫谈对局中近战武器的攻击网络同步
    企业知识库软件,快速构建企业知识分享与团队协同的软件
    【性能优化下】组织结构同步优化二,全量同步/增量同步,断点续传实现方式
    李沐动手学深度学习V2-RNN原理
    HypeX Labs:充分释放加密资产的潜力
    Jmeter(四) - 从入门到精通 - 创建网络测试计划(详解教程)
    MySql 笔记
  • 原文地址:https://blog.csdn.net/lk142500/article/details/133773464