cling 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 clinging on by her fingernails until the rescue crew arrived.
2. By extension, to narrowly avoid problems or failure. They're clinging 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 clinging on by my fingernails every day.