如何解决在bash shell脚本错误? [英] How to fix the error in the bash shell script?

查看:206
本文介绍了如何解决在bash 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:

快照管理单元5E20卷-F660完成2013-12-10T08:00:30 + 0000 100%109030037527 10 2013年12月10号:每日备份的I-2111(VolID:第一卷,f9a0 InstID:I-2601)

这将包含类似这样的记录

It will contain records like this

我得到这个code:

latestdate = $(EC2-描述,快照| grep的^快照|排序-k 5 | awk的'{打印$ 5}') EC2-描述,快照| grep的快照* $ latestdate。| > $ EC2_HOME / SnapshotsLatest_ $ today_date

latestdate=$(ec2-describe-snapshots | grep ^SNAPSHOT | sort -k 5 | awk '{print $5}') ec2-describe-snapshots | grep SNAPSHOT.*$latestdate | > "$EC2_HOME/SnapshotsLatest_$today_date"

但得到这个错误:

的grep:2013-12-10T09:55:34 + 0000:没有这样的文件或目录 grep的:2013-12-11T04:16:49 + 0000:没有这样的文件或目录 grep的:2013-12-11T04:17:57 + 0000:没有这样的文件或目录

grep: 2013-12-10T09:55:34+0000: No such file or directory grep: 2013-12-11T04:16:49+0000: No such file or directory grep: 2013-12-11T04:17:57+0000: No such file or directory

我已经在亚马逊一些快照,我想寻找的日期最新的快照,然后希望将它们存储在一个文件中。就像迄今为止在这个日期2013年12月10号的快照应存放在文件中。 snapshotslatest文件的内容应该是

i have some snapshots made on amazon, i want to find the latest snapshots made on a date and then want to store them in a file. like date 2013-12-10 snapshots made on this date should be stored in file. Contents of snapshotslatest file should be

快照管理单元c17f3卷-f69a0完成2013-12-04T09:24:50 + 0000 100%109030037 527 10 2013年12月4日:每日备份的Sanjay_Test_Machine(VolID:第一卷,f66409a0 InstID:I-26048111) 快照管理单元c7d617f9卷-3d335f6b完成2013-12-04T09:24:54 + 0000 100%1090 30037527 10 2013年12月4日:每日备份的sacht_VPC(VolID:卷的-3dB InstID:I-ED6)

SNAPSHOT snap-c17f3 vol-f69a0 completed 2013-12-04T09:24:50+0000 100% 109030037‌​527 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% 1090‌​30037527 10 2013-12-04: Daily Backup for sacht_VPC (VolID:vol-3db InstID:i-ed6)

请注意,如果有关于创建的快照二零一三年十二月十日,二○一三年十二月一十一日,二零一三年十二月十二日。这意味着,latest_date应 2013年12月12日和所有上创建的snaphshot 2013年12月12日应被保存在文件中。

please not that if there are snapshots created on 2013-12-10, 2013-12-11, 2013-12-12. It means that the latest_date should be 2013-12-12 and all the snaphshot created on 2013-12-12 should be saved in file.

任何建议或铅是AP preciated。

Any suggestion or lead is appreciated.

推荐答案

无论是批处理脚本,也不您发布的shell脚本是一个很好的起点,让我们从头开始。对不起,这是太大的意见。

Neither the batch script nor the shell script you posted are a good starting point so let's start from scratch. Sorry, this is too big for a comment.

要寻找的日期最新的快照,然后想将它们存储在一个文件

这是什么意思?

执行快照文件的时间戳在其名称或者其内容?

Do the snapshot files have a timestamp in their name or in their content?

如果不是 - ?UNIX不存储文件的创建时间戳等是上次修改的时间戳足够

If not - UNIX does not store file creation timestamps so is a last-modified timestamp adequate?

你硬是要连接您的所有快照文件到一个燎文件或者你想创建一个具有快照文件名列表的文件?

Do you literally want to concatenate all of your snapshot files into one singe file or do you want to create a file that has a list of the snapshot file names?

发表一些样本输入(例如,一些快照文件的名称和内容,如果这也正是时间戳存储),并考虑到输入,预期的输出

Post some sample input (e.g. some snapshot file names and contents if that's where the timestamp is stored) and the expected output given that input.

更新你的问题,以解决上述所有的,不要试图在注释中回复。

Update your question to address all of the above, do not try to reply in a comment.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆