0
我想在shell脚本中的代码。而我试图将代码从批处理脚本转换为shell脚本,我收到一个错误。shell脚本错误?
批处理文件代码
:: 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 IN shell脚本
#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"
我想根据日期,并保存在最新的创建日期在文件快照快照进行排序。作者
样本输出ECE-描述的快照:
`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)`
它将包含的记录,像这样
的snaphsot最新文件应该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)
任何建议或铅认识。
你得到什么错误? Shell区分大小写,使用'for'而不是'FOR'。 – choroba
描述你想要做什么并提供输入数据和期望的输出。 –
我有一些在亚马逊拍摄的快照,我想找到在某个日期做出的最新快照,然后将它们存储在一个文件中。像日期2013-12-10在这个日期做的快照应该存储在文件中。 snapshotslatest文件的内容应该是'快照\t卡扣c17f3 \t体积-f69a0 \t \t完成2013-12-04T09:24:50 + 0000 \t 100%\t 2013年12月4日:用于Sanjay_Test_Machine每日备份(VolID :体积-f66409a0 InstID:I-26048111) 快照\t卡扣c7d617f9 \t体积-3d335f6b \t \t完成2013-12-04T09:24:54 + 0000 \t 100%\t 2013年12月4日:每日备份对于sacht_VPC(VolID:vol-3db InstID:i-ed6) ' – user3086014