Kizmet is right. Sounds like a thermocouple. A thermocouple senses the heat of the flame with a bimetal element. The element creates a small electric charge which is sent to a small magnet inside the gas valve. This magnet holds open the plunger valve. The valve lets gas flow to the burner and the pilot tube. Once the thermocouple looses the ability to send a full electrical charge to the plunger, the plunger drops and closes off the electricity. The first step is to make sure the thermocouple tip is all the way into the flame. If its not quite in it, sometimes it will create just barely enough to hold the plunger. But if the air starts being drawn up the chimney from the flue, cool air enters the burner area and draws it across the thermocouple cooling it. If that doesnot solve the problem, then you will have to replace the thermocouple. If that does not solve the problem, you may have to replace the plunger and/or gas valve. I have had them go bad (not very often).