1

I'm designing some reporting system on Raspberry Pi system which connects to world thru 3G usb modem controlled by pppd.

99,999% of time connection works ok, but sometimes it drops and further reconnect attempts fail unless modem is re-plugged physically.

As in production box will work remotely with no physical access to it so I have to manage it somehow.

My idea is to run at system start, some kind of script in separate thread see below pseudocode:

while(true){
  wait_for_modem_device_to_appear
  start_pppd # may_be limiting retries not to default 10, but to, say, 3
  wait_for_pppd_to_finish
  if(exitcode_is_one_of(6,7,8,10,15,16)){
    reset_usb_port_programmatically #I have tools for that
  }else{
    break
  }
}
  • How can I get pppd exit code?
  • Should I use another approach (which)?
0

After calling 'pppd' you need get value of variable '$?'.

$? - get exit code of last program.

For background processes '$!' may be useful with some cover.

$! - get PID of last background process that was executed.

Example scenario:

run_background_process &
pid_of_background_process=$!
wait $pid_of_background_process
echo "Result code of background process: "$?
  • Yury, ppd is running on background so you will get 0 always – DmitryD Mar 6 '18 at 14:18
  • @DmitryD, I've supplemented answer. – Yurij Goncharuk Mar 6 '18 at 14:39
  • Solution you proposed doesn't work even with supplement, but thanks for your try! – DmitryD Mar 14 '18 at 17:05
0

Bingo!

Put 'nodetach' as command-line argument to pppd and daemon will not fork itself. All is needed then is standard 'echo $?' in next line of script:

pppd call my_provider nodetach maxfail 3
echo $?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.