LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   check internet connection in .bashrc (http://www.linuxquestions.org/questions/linux-newbie-8/check-internet-connection-in-bashrc-386739/)

mvo 11-26-2005 02:37 PM

check internet connection in .bashrc
 
I want to start certain applications automatically after login when there is a network /internet connection.

I thought of checking the network connection in .bashrc , but what code should I include to do the job or what other ways could be recommandable?

Cheers, Marcel

jailbait 11-26-2005 05:26 PM

"I thought of checking the network connection in .bashrc , but what code should I include to do the job or what other ways could be recommandable?"

Issue the dig command and check the return code. A zero return code means that you are connected to the Internet.

if test dig > /dev/null ;
then
start some applications
fi

I don't know what dig returns when on a network which is not connected to the Internet. You can test the possibilities with:

dig
echo $?

See:
man dig


----------------------
Steve Stites

Electro 11-26-2005 07:32 PM

The utility dig is only use to verify the setup of DNS servers. The utility wget could be use to check certain servers like mail or other servers. The command below gives an example that you could use.

wget -nv --spider [server address]

Then use the code that it prints out to find out if it has successfully connected to the server.


All times are GMT -5. The time now is 11:52 PM.