本文介绍了在shell脚本错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个code的shell脚本。而我想转换code从批处理脚本shell脚本,我得到一个错误。

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.

批处理文件code

:: Create a file with all latest snapshots
FOR /F "tokens=5" %%a in (' ec2-describe-snapshots ^|find "SNAPSHOT" ^|sort /+64') do set "var=%%a"
set "latestdate=%var:~0,10%"
call ec2-describe-snapshots |find "SNAPSHOT"|sort /+64 |find "%latestdate%">"%EC2_HOME%\Working\SnapshotsLatest_%date-today%.txt"

code。在shell脚本

CODE IN SHELL SCRIPT

#Create a file with all latest snapshots
FOR snapshot_date in $(' ec2-describe-snapshots | grep -i "SNAPSHOT" |sort /+64') do set "var=$snapshot_date"
set "latestdate=$var:~0,10"
ec2-describe-snapshots |grep -i "SNAPSHOT" |sort /+64 | grep "$latestdate">"$EC2_HOME%/SnapshotsLatest_$today_date"

我想根据日期,并保存在最新的日期在文件中创建的快照快照进行排序。

I want to sort the snapshots according to dates and to save the snapshots that are created in latest date in a file.

样品输出ECE-描述-快照:

SAMPLE OUTPUT OF ece-describe-snapshots:

`SNAPSHOT        snap-5e20   vol-f660    completed       2013-12-10T08:00:30+0000        100%    109030037527    10      2013-12-10: Daily Backup for i-2111 (VolID:vol-f9a0 InstID:i-2601)`

这将包含类似这样的记录

It will contain records like this

在snaphsot最新的文件应该cointain:

the snaphsot latest file should cointain:

SNAPSHOT    snap-cdd617f3   vol-f66409a0    completed   2013-12-04T09:24:50+0000    100%    109030037527    10  2013-12-04: Daily Backup for Sanjay_Test_Machine (VolID:vol-f66409a0 InstID:i-26048111)
SNAPSHOT    snap-c7d617f9   vol-3d335f6b    completed   2013-12-04T09:24:54+0000    100%    109030037527    10  2013-12-04: Daily Backup for sachin_test_VPC (VolID:vol-3d335f6b InstID:i-e1c443d6)

任何建议或铅是AP preciated。

Any suggestion or lead is appreciated.

推荐答案

它,你必须运行该命令两次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"

这篇关于在shell脚本错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 13:04