error in shell scripting?

后端 未结 1 949
野趣味
野趣味 2020-12-12 07:26

I am trying a code in shell script. while I am trying to convert the code from batch script to shell script I am getting an error.

BATCH FILE CODE

:         


        
相关标签:
1条回答
  • 2020-12-12 08:09

    Its a code smell that you have to run the command twice.

    It was unclear that you wanted just the lines for the most recent day. Try this:

    ec2-describe-snapshots | sort -rk 5 | awk '
        $1 != "SNAPSHOT" {next}
        NR == 1 { split($5, a /T/); date = a[1]; }
        $5 ~ date {print}
    ' > "$EC2_HOME/SnapshotsLatest_$today_date"
    

    If you only want today's snapshots, even easier

    today=$(date +%F)
    ec2-describe-snapshots | sort -rk 5 | awk -v date=$today '
        $1 == "SNAPSHOT" && $5 ~ date {print}
    ' > "$EC2_HOME/SnapshotsLatest_$today"
    
    0 讨论(0)
提交回复
热议问题