Aws-cli: aws s3 sync - know definitively if the sync completed successfully?

Created on 27 Jan 2015  路  4Comments  路  Source: aws/aws-cli

Hi, I am trying to automate syncing - it would be enormously helpful if the command line returned a statement in the last line of output that simply indicates if the entire sync operation was 100% success or not. Thank you

Most helpful comment

If you're trying to automate syncing, you can check the return code of the process. For s3:

0 - no errors
1 - s3 could not sync all files
2 - warnings were emitted (e.g if files were skipped because we didn't have permissions to read the file)

All 4 comments

If you're trying to automate syncing, you can check the return code of the process. For s3:

0 - no errors
1 - s3 could not sync all files
2 - warnings were emitted (e.g if files were skipped because we didn't have permissions to read the file)

That sounds perfect. However, could you tell me how to get that? When I run a sync command I get a long list of what it did, which is helpful, but how do I capture the return code? I don't see that at the end of the output at the command line.

For most shells you can use $? to check the status code:

# Sync a normal file, we'll get a 0 rc
/tmp $ echo hello world > test/foo.txt
/tmp $ aws s3 sync test/ s3://$BUCKET/
upload: test/foo.txt to s3://jamesls-test-sync/foo.txt
/tmp $ echo $?
0

# Now if we try to sync a file we can't read, like a fifo in this example, we'll get an RC of 2:
/tmp $ mkfifo test/badfifo
/tmp $ aws s3 sync test/ s3://$BUCKET/
warning: Skipping file /private/tmp/test/badfifo. File is character special device, block special device, FIFO, or socket.
Completed 0 part(s) with ... file(s) remaining
/tmp $ echo $?
2

Terrific, thank you

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kangman picture kangman  路  3Comments

maanbsat picture maanbsat  路  3Comments

ronaldpetty picture ronaldpetty  路  3Comments

motilevy picture motilevy  路  3Comments

rahul003 picture rahul003  路  3Comments