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
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
Most helpful comment
If you're trying to automate syncing, you can check the return code of the process. For s3: