hang on by (one's) fingernails
1. Literally, to grasp something, such as a cliff, with one's fingernails to avoid falling. The stranded hiker was hanging on by her fingernails until the rescue crew arrived.
2. By extension, to narrowly avoid problems or failure. They're hanging on by their fingernails out there—the other team's offensive is totally overwhelming them. Now that I have three small children to care for, I feel as if I'm hanging on by my fingernails every day.