I have a shell script which needs to run in the background all day 24*7, but it fails for every 24 hours with error: /bin/mkdir: Argument list too long. As a workaround, I will re-run the script in the background and it runs for 24 hours and then again it fails with the same error.
When i say it runs for 24 hours means, this script gets triggered for every 30 mins and it completes successfully, this continues for a 24 hour period, then it fails and then it will not run. Here i have to manually restart the script, then it runs for 24 hours and fails.>
For the successful and failure run, the dir_path values are same.
To fix this issue I modified my code to create mkdir command as:
echo ${dir_path} | xargs mkdir -p >> ${log_path}/${log_file} 2>&1 but no luck.
Any inputs or idea will be helpful.
131 Answer
It is hard to get that error when you are using xargs. It should protect you against this error if it can. However, if you fill up your entire environment with data, there is no space left for even a single mkdir call. It's all full, and the system has no other option than giving you an error.
Exported variables count towards your argument list size.
I think what is happening is that you are using "export var=something" to put data in your environment. This data is growing over time. Maybe it's an array?
You can use this to debug your sizes:
echo | xargs --show-limits It's just a guess. I can't know for sure if you are not sharing all your code.
1