rubing Posted September 27, 2008 Share Posted September 27, 2008 Yo homeys. I am a linux programming noob, greener than your lawn, although i do know php, so not a complete rube. I am hoping I can get some help on writing my first script. I am using a blackberry to get internet on my laptop (tethering). I am damn damn sick and damn damn infuriated at having to always type the commands manually. So, I wrote the following script: #!/bin/bash bcharge pppd call barry-sprint& This works, but is not really robust. First, I really need to be able to check whether or not bcharge finds a phone plugged in. If it doesn't detect anything then i'd want to wait a couple secs and try again, before failing gracefully. Well, you don't need to hear about all that. Basically I just want to know how to check whether the phone is plugged in. Is this what they call exit status?? Quote Link to comment https://forums.phpfreaks.com/topic/126054-check-exit-status/ Share on other sites More sharing options...
trq Posted September 28, 2008 Share Posted September 28, 2008 You can check the exit status of the last command executed by looking at the $? variable. 0 meens success, anything else is some sort of error. eg; #!/bin/bash bcharge if [ "$?" -eq 0 ] ; then echo "bcharge successfull" pppd call barry-sprint & fi You can also chain commands together using && (and) or || (or). eg; #!/bin/bash bcharge && pppd call barry-sprint & This will only execute pppd call barry-sprint & if bcharge is successfull. As for whether or not bcharge finds a phone plugged in, the first thing I would do would be to manually look for it within your /dev directory. Quote Link to comment https://forums.phpfreaks.com/topic/126054-check-exit-status/#findComment-652259 Share on other sites More sharing options...
rubing Posted September 30, 2008 Author Share Posted September 30, 2008 Hey Thorpe! How's the php 5.3 install working? well, I changed that script to read as follows: Script blacknet: #!/bin/bash #start bcharge up and send any output to the void bcharge &> /dev/null THERE=$? echo "checking for phone..." if [ $THERE -eq 0 ]; then echo "yay, we found you're phone" #kill any running instances of ppp, before starting it up pkill ppp* pppd call barry-sprint& else echo "boo, we didn't find jack" #this needs to sleep and check again first fi It works, but it runs entirely in the background. So that if I type blacknet. I get returned to a prompt and then as commands get executed they pop up. I would rather the program take away the prompt until its finished running. Quote Link to comment https://forums.phpfreaks.com/topic/126054-check-exit-status/#findComment-654145 Share on other sites More sharing options...
trq Posted September 30, 2008 Share Posted September 30, 2008 Remove the & from this line.... pppd call barry-sprint& Quote Link to comment https://forums.phpfreaks.com/topic/126054-check-exit-status/#findComment-654275 Share on other sites More sharing options...
rubing Posted October 1, 2008 Author Share Posted October 1, 2008 hmmm...this isn't quite doing what I want, b/c the prompt is not returned at the very end. It just kind of hangs there saying: /etc/ppp/ip-up finished Quote Link to comment https://forums.phpfreaks.com/topic/126054-check-exit-status/#findComment-654372 Share on other sites More sharing options...
trq Posted October 1, 2008 Share Posted October 1, 2008 You need to exit the script at the end. eg; exit 0 Quote Link to comment https://forums.phpfreaks.com/topic/126054-check-exit-status/#findComment-654399 Share on other sites More sharing options...
rubing Posted October 7, 2008 Author Share Posted October 7, 2008 That doesn't work either. Is there a command to take away the command prompt?? Quote Link to comment https://forums.phpfreaks.com/topic/126054-check-exit-status/#findComment-659035 Share on other sites More sharing options...
trq Posted October 7, 2008 Share Posted October 7, 2008 You can kill it by setting it to an empty string. Seems a hack though. PS1="" You might want to store the current prompt in a temp var so you can restore it when your done. eg; TMP="$PS1" PS1="" ## do your thing PS1="$TMP" Quote Link to comment https://forums.phpfreaks.com/topic/126054-check-exit-status/#findComment-659055 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.