As soon as Arduino is on GSM starts establishing so I have put a delay in after startup to give the shield chance to get GSM before doing the if/else.
MODEM STARTUP()
Force modem off - in case it has been left on.
Test / check that is actually OFF(AT\r...OK).
Then turn the modem 'ON' again ... using hardware 'power' pin.
Sit in a local while loop for x seconds - retrying "AT\r" until you get the "OK" response.
Run through your modem initialisation commands - waiting each time for the "OK" response
After this is complete - you're ready to go...
If the modem fails to respond to commands while running - run the MODEM STARTUP function again.
At each stage - you may use local counters to avoid endless loops.
So you can exit and kick start the process if any process fails after 'n' attempts.
Also useful to Serial.print() status after each fail attempt.
For example, I test for 5 retries when sending a message, then drop the message from the queue, or if the modem report another issue, I restart the modem, and resume the same sequence (for a number of retries), then drop that command and turn off the modem(first), and reset the whole Arduino with the hardware watchdog.
My boxes live in remote rural locations, and (touch wood) have never needed human intervention.
Once you get it sorted out - it's also useful to log major events - then you can query the device to see how many success/fail events, power failures, resets and other things have happened since the log was last cleared.