Tiny Core Extensions > TCE Tips & Tricks

Starting wifi when no Ethernet exists by script.

(1/3) > >>

coreplayer2:
So we fire up the notebook at home, work or hotel and have to go through a couple of steps to get connected.  Having gone through this several times a day, I can tell you it gets old fast.   I figured how about we make this task more automated, like make a script to check for an Ethernet connection (because sometimes there is a loose cable on the desk) then quit if true, or start the wifi.sh script if false.   

This script I place in my home/tc/scripts dir and start it from X.d with a small delay.   Now when my notebook starts I receive a selection of Access Points to choose from or use it as a reminder that I forgot to connect an Ethernet cable.  doh!

#!/bin/sh
#Checks for LAN connectivity then start wifi if needed

eth_f (){
if [ -d /sys/class/net/eth0 ]; then
ETH=`cat /sys/class/net/eth0/carrier`
fi
}
eth_f;
sleep 1
if [ -z "$ETH" ] || [ "$ETH" != 1 ]; then
        if [ -d /sys/class/net/wlan0 ]; then
      cliorx sudo wifi.sh
      exit 1
   fi
        exit 2
fi
exit 0


Ideally, I'd like to start the script outside of X  but am still perfecting that...  :|


ps. scrapped this script in favor of the one in last post

curaga:
I'd check `cat /sys/class/net/eth0/carrier` instead, isn't eth0 still brought up even without a cable connected?

coreplayer2:
Cool thanks, that's exactly what I was looking for.  ;D  (Had previously tried ping without success.. lol)

Ethernet adapter without LAN connectivity, carrier contents = 0
Ethernet adapter with LAN connectivity, carrier contents = 1


This is perfect,  have modded script
 Thanks again

ps but wait this assumes an Ethernet adapter installed..

Rich:
Hi coreplayer2

--- Quote ---but wait this assumes an Ethernet adapter installed..
--- End quote ---
You could set   ETH=0   and then test if   /sys/class/net/eth0/carrier   exists. If it does, you read it,
if it doesn't you don't.

coreplayer2:
thanks guys,  I followed your suggestions and have come up with a new plan,  the short version above replaces the original and then this version with a notification if no wifi or eth exists,
just in case I wanted feedback..

#!/bin/sh
#Check for LAN connectivity then starts wifi if needed

eth_f (){
if [ -d /sys/class/net/eth0 ]; then
ETH=`cat /sys/class/net/eth0/carrier`
fi
}
wlan_f (){
if [ -d /sys/class/net/wlan0 ]; then
WLAN=`cat /sys/class/net/wlan0/carrier`
fi
}

eth_f;
wlan_f;
sleep 1
if [ -z "$ETH" ] || [ "$ETH" != 1 ]; then
   if [ -n "$WLAN" ] && [ "$WLAN" = 0 ]; then
      cliorx sudo wifi.sh
      exit 1
   fi
   popup "No Ethernet or Wireless connections available"
   exit 2
fi
exit 0

Speaking of feedback, I think someone mentioned notify or popup or something..?

ps. also scrapped this variation in favor of the script in last post

Navigation

[0] Message Index

[#] Next page

Go to full version