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
:
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"