Control of transistor as switch at power up and power down
Without going into too much detail I would consider the exclusive or gate edge detector circuit: -



This can be scaled up in time by using much bigger values for the capacitor and resistor of course. See also this answer for a rising/falling edge detector - it goes into more detail.