Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在linux中获取文本文件中最新快照的详细信息?_Linux_Shell_Batch File_Amazon Ec2 - Fatal编程技术网

如何在linux中获取文本文件中最新快照的详细信息?

如何在linux中获取文本文件中最新快照的详细信息?,linux,shell,batch-file,amazon-ec2,Linux,Shell,Batch File,Amazon Ec2,我有一个包含代码的批处理脚本 :: 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

我有一个包含代码的批处理脚本

:: 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"
我需要将批处理脚本转换为linux shell脚本。我该怎么做呢。我需要获取在最新日期创建的所有最新快照的信息。如2013年12月10日(日期格式)

谢谢

您可以尝试:

#!/bin/bash 
#
LATESTDATE=`ec2-describe-snapshots | grep "SNAPSHOT" | awk '{print $5}' | sort | cut -d "T" -f 1 | tail -1`
ec2-describe-snapshots | grep "SNAPSHOT" | grep ${LATESTDATE} > ~/SnapshotLatest_`date`.txt

提供输入数据和输出要求我在amazon上制作了一些快照,我想找到在某个日期制作的最新快照,然后将它们存储在文件中。如2013年12月10日,在该日期制作的快照应存储在文件中。snapshotslatest文件的内容应为“SNAPSHOT snap-c17f3 vol-f69a0 completed 2013-12-04T09:24:50+0000 100%109030037‌​527 10 2013-12-04:Sanjay_测试机器的每日备份(卷ID:vol-f66409a0 Institd:i-26048111)快照snap-c7d617f9卷3d335f6b已完成2013-12-04T09:24:54+0000 100%1090‌​30037527 10 2013-12-04:sacht_VPC的每日备份(卷ID:vol-3db Institd:i-ed6)