Reputation: 3278
I have created a a batch script which has following content. But the script terminates after executing the first statement. I have googled a lot but couldn't find anything helpful.However the individual statements can be executed separately. PFB the script
Any suggestion is appreciated.
set AWS_SNAPSHOT_KEEP=1
:: Create a file with all attached volumes
::ec2-describe-volumes|find /i "attached">%EC2_HOME%\Volumes.txt
:: Create snapshot for this volume
for /f "tokens=2" %%s in (%EC2_HOME%\Volumes.txt) do ec2-create-snapshot %%s
:: Find old snapshots for this volume.
for /f "tokens=2" %%s in (%EC2_HOME%\Volumes.txt) do ec2-describe-snapshots --filter "volume-id=%%s">%EC2_HOME%\Snapshots.txt
::Copy Snapshot across multiple regions.
for /f "tokens=2" %%s in (%EC2_HOME%\Snapshots.txt) do ec2-copy-snapshot -r us-west-2 -s %%s -region us-east-1
:: Loop over old snapshots, skip the first 1, delete the rest
for /f "tokens=2 skip=%AWS_SNAPSHOT_KEEP%" %%s in (%EC2_HOME%\snapshots.txt) do ec2-delete-snapshot %%s
Thanks and regards, Jyoti
Upvotes: 2
Views: 1555
Reputation: 7192
ec2-create-snapshot
and friends are themselves batch scripts, if they are the Amazon EC2 API Tools that I found online. They happen to call exit
when they are done. This is exiting your batch script as well.
Instead, try using call
before the ec2 commands.
for /f "tokens=2" %%s in (%EC2_HOME%\Volumes.txt) do
call
ec2-create-snapshot %%s
Apply as needed to the other ec2 commands.
For details see the output of help exit
and help call
.
A common idiom to sleep in batch is to ping the local machine:
@ping -n 2 -w 1000 127.0.0.1 > NUL
This "sleeps" for about 2 * 1000 milliseconds = 2 seconds by pinging the local machine twice with a delay of 1 second between each. Add this as needed.
Upvotes: 6