There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Tag Cloud
acer backup bios boot bsod compaq computer connection crash dell desktop driver drivers email error excel firefox format freeze hard drive hardware hijackthis internet kb977165 keyboard laptop linksys mac malware network outlook outlook 2003 outlook 2007 problem realtek slow sound toshiba trojan usb video virus vista vpn windows windows 7 windows vista windows xp wireless word 2007
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
bash script with windows?

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
Bigjohn123's Avatar
Member with 30 posts.
 
Join Date: Jul 2007
14-Oct-2007, 11:16 AM #1
bash script with windows?
I didn't know where to post this, since it deals with both UNIX & windows.

Anyway, is there a way to run this script on windows xp?
Code:
#!/bin/bash
# Finds the strongest unencrypted AP and tries to connect to it via dhcp
# Call this script like "wifi.sh wlan0"
TEMP=/tmp/bestap.tmp
LOCK=/var/lock/bestap.lock
if [ `whoami` != "root" ];then
        echo "Sorry, you need to be root to run this program"
        exit 1
fi

if [[ -z $1 ]];then
        echo "USAGE: $0 device"
        exit 1
else
        interface=$1
fi

# Checking for lock
if [[ -e $LOCK ]];then
        exit 1; # Too simply nothing to do here :)
else
        touch $TEMP $LOCK
fi


# Proggy
iwlist $interface scan > $TEMP
NumAPs=`cat $TEMP | grep ESSID | wc -l`
BestAP=0
BestQuality=-1
for i in `seq 1 $NumAPs`;
do
   # Check if AP is encrypted
   Encryption=`cat $TEMP | grep Encryption | head -n$i | tail -n1 | cut -d":" -f2`
   if [ $Encryption = "off" ]; then
      # Find AP with the highest quality
      QUALITY=`cat $TEMP | grep Quality | head -n$i | tail -n1 | cut -d":" -f2 | cut -d"/" -f1 | sed 's/ //g'`
      if [ "$QUALITY" -gt "$BestQuality" ]; then
         BestQuality=$QUALITY
         BestAP=$i
      fi
   fi
done
if [ $BestAP -gt 0 ]; then
   # Yay, we found an unencrypted AP:
   echo Connecting to...
   ESSID=`cat $TEMP | grep ESSID | head -n$BestAP | tail -n1 | cut -d""" -f2`
   echo ESSID=$ESSID
   MODE=`cat $TEMP | grep Mode | head -n$BestAP | tail -n1 | cut -d":" -f2`
   echo Mode=$MODE
   CHANNEL=`cat $TEMP | grep Channel | head -n$BestAP | tail -n1 | cut -d"(" -f2 | sed 's/Channel //g' | sed 's/)//g'`
   echo Channel=$CHANNEL
   # Connect
   iwconfig $interface essid $ESSID mode $MODE channel $CHANNEL
   if [ -e /etc/dhcpc/dhcpcd-${interface}.pid ]; then
      rm /etc/dhcpc/dhcpcd-${interface}.pid
   fi
   dhcpcd $interface
   # Cleanup
fi
rm -f $TEMP $LOCK
Also, would anyone know how to make this file executable? I know the code to do it, but I do not know where to place it in the script.

thanks!
lotuseclat79's Avatar
Distinguished Member with 16,008 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
14-Oct-2007, 11:47 AM #2
If you download and install the Cygwin environment for Windows you may be able to execute the script.

Within a Cygwin terminal window you might be able to issue the chmod command to make the script executable:
# chmod 700 scriptname
i.e. in a Unix-like environment, the chmod command is issued to make a shell file executable, i.e. which you could do from within a script that you generate, or issue a command like:
# sh scriptname
where the 'sh' script is a link to the 'bash' shell executable.

I base these statements on:
1) I think Cygwin has a bash shell - but, I do not know for sure.
2) If Cygwin has a bash shell, it might have a chmod command as well - but, I do not know for sure.

Note: The Cygwin gcc compiler would have to be able to compile those commands for this to work, i.e. the bash shell, and the chmod command.

Here is a link to Cygwin where you may be able to find the answers to those questions in the FAQ: http://www.cygwin.com

-- Tom
__________________
The independence created by philosophical insight is - in my opinion - the mark of distinction
between a mere artisan or specialist and a real seeker after truth. - Einstein 1944
Imagination is more important than knowledge. - Einstein
Bigjohn123's Avatar
Member with 30 posts.
 
Join Date: Jul 2007
14-Oct-2007, 12:56 PM #3
thanks
It worked, thanks! I have cygwin, but I never knew where to issue the chmod command. Now I know, thanks again.
Closed Thread Bookmark and Share   techguy.org/637948

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 09:50 AM.
Copyright © 1996 - 2010 TechGuy, Inc. All rights reserved.
Powered by Cermak Technologies, Inc.