I'm trying to limit the time it takes for curl to upload a file to 30 seconds, but I'm not sure where I'm going wrong. Here's the code I'm using: I run a loop where I echo an upload attempt message, then use curl with parameters for connect timeout and max time, and log the output. After each attempt, I touch a file to keep the system from rebooting due to inactivity. However, despite setting these time limits, the curl log shows a 10-minute gap between the start and end times, which doesn't align with my expectations. The log indicates that curl properly times out after 30 seconds, but I don't understand why there's such a long delay before I see the upload failed message. Can someone help clarify what's happening?
3 Answers
It looks like the server authenticated your request but then timed you out after 30 seconds with no data being transferred. Have you considered using standard SSH tools like scp or sftp instead of curl for your file uploads? They are typically more suited for this kind of operation. Additionally, you could explore other timeout handling methods in your script to avoid too much reliance on curl's settings.
If you're looking for more control over time limits in your script, consider trying to manage it through shell scripting rather than depending solely on curl's timeout options. You could implement checks to monitor the execution time of each command. Also, simplifying your script to focus on just what you need might reveal any hidden issues you have with your current setup.
Curl did actually time out after the 30 seconds you set. The long delay you're seeing is due to the way your loop and logging are structured, not because curl is ignoring the max time limit. Essentially, the timestamps in your log don't indicate that curl took a long time; they're just showing you that the rest of your loop takes additional time to execute. Adding timing commands around your curl execution can help you see how long curl is really running, and you might discover it's around that 30 seconds you expected.

Great explanation! So instead of looping, would using curl's built-in retry option be a better approach? That would help me manage time better and adjust the watchdog settings appropriately. Just a heads up, my Raspberry Pi captures images every two minutes, and it can freeze sometimes due to the USB connection, so I have to touch an image file to avoid reboots.