简体   繁体   中英

aws cli hangs when in background

I have a command which runs pretty well when I just run it:

time aws sqs send-message --queue-url https://my_sqs_url --message-body "$(date "+%H:%M:%S_%N")"
{
    "MD5OfMessageBody": "a19f365993d45d4885f7f15bce8aac97",
    "MessageId": "30971fa7-d8ac-4540-9541-aebc38598856"
}

real    0m1.321s
user    0m1.174s
sys     0m0.117s

If I want to run in in background then the sqs message is sent however the process hangs infinitely (or at least I'm not patient enough to see when it eventually ends):

aws sqs send-message --queue-url https://my_sqs_url --message-body "$(date "+%H:%M:%S_%N")" &
[1] 9561

During that I see two processes instead of one:

ps -eFH | grep "aws sqs"
root      9561  2980  0  2210   912   1 09:29 pts/0    00:00:00         aws sqs send-message --queue-url https://my_sqs_url --message-body 09:29:30_009996044
root      9563  9561  0 63048 59172   1 09:29 pts/0    00:00:01           aws sqs send-message --queue-url https://my_sqs_url --message-body 09:29:30_009996044

The questions: why it hangs and how to do it properly?

This should work:

time aws sqs send-message --queue-url https://my_sqs_url --message-body "$(date "+%H:%M:%S_%N")" & wait $!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM