【问题标题】:shell scripts: pass curl result as parameter to shell scriptshell 脚本:将 curl 结果作为参数传递给 shell 脚本
【发布时间】:2021-03-17 05:51:03
【问题描述】:

我想将 curl 结果作为参数传递给另一个脚本,比如脚本delete-app.sh

 #!/bin/sh

SERVICE_HOST=localhost
SERVICE_PORT=9200

delete(){
    echo "entered  here"
    if [ $# -lt 2 ]; then
        echo "usage: $0 delete [--name] [index_name]"
        exit 1
    fi

    case "$1" in
        --name)
            index_name=$2
        ;;
        *)
        echo "Unknown argument $1"
        exit 1
        ;;
    esac
    echo $index_name
}


if [ $# -eq 0 ]; then
    echo "Usage: $0 (delete)"
    exit 1
fi

case "$1" in
  delete)
    delete $2 $3
    ;;
  *)
    echo "Unknown argument $1"
    exit 1
    ;;
esac

exit 0

运行以下命令

 ./delete_app.sh delete --name `curl -s "http://<host>:<port>/_cat/indices/applicationevent*" | awk -F ' ' '{print $3}' | cut -c18- | awk -v d=`date -d'10 days ago' +'%Y.%m.%d'` -F'|' '$1 < d' | awk '{print "applicationevent-" $1 }' |paste -s -d, -

这里我为 --name 获取的参数来自 curl 命令结果,但现在结果没有出来。

【问题讨论】:

    标签: shell curl


    【解决方案1】:

    下面的方法工作正常

    ./delete_app.sh delete --name $(curl -s "http://<host>:<port>/_cat/indices/applicationevent*" | awk -F ' ' '{print $3}' | cut -c18- | awk -v d=`date -d'10 days ago' +'%Y.%m.%d'` -F'|' '$1 < d' | awk '{print "applicationevent-" $1 }' |paste -s -d, -)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多