LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-08-2012, 07:23 AM   #1
boscop
LQ Newbie
 
Registered: Mar 2012
Posts: 11

Rep: Reputation: Disabled
awk error awk: line 2: missing } near end of file


Hi, please can anyone give me some help here
I am trying to do a if stament using awk but I keep having this error awk: line 2: missing } near end of file

and this is the part of the code

echo "$scanning_card_signal_quality $ROAMING_THRESHOLD_WLAN0 $connected_card_signal_quality" | awk '{if (($1 > $2) && ($3 < $2)) {'
echo "Starting handover from $connected_card to $scanning_card"
start_handover=$(date +%s.%N)
sudo iwconfig $scanning_card essid 'HTC network'
end_handover=$(date +%s.%N)
time_delay=$(echo "$end_handover - $start_handover" | bc)
echo "Handover time delay is $time_delay nanoseconds"
# sudo dhclient $WLAN0
sudo dhclient $connected_card
# sudo ip addr add 192.168.1.136/24 dev $scanning_card
sudo ping -c4 google.com #ping command to check the connection
echo "line 64"
#sudo ip link set down $connected_card
sudo dhclient -r $connected_card
sudo ip link set up $connected_card
temp=$connected_card
connected_card=$scanning_card
scanning_card=$temp'}'



AND THIS IN THE ENTIRE CODE

#!/bin/sh -ux
clear

echo "This script control the wireless interface during handover"
echo

sleep 2
connected_card="wlan0"
scanning_card="wlan1"

echo "Starting wireless interface one"
sleep 2
sudo ip link set $connected_card down
sudo dhclient -r $connected_card
sudo ip link set $connected_card up

echo "$connected_card is scanning the network"
sudo iwconfig $connected_card | grep level
echo "line 19"
#echo "Connecting $connected_card to a network with highest signal "$ACCESS_POINT_HIGHSIG1

# will replace the above command for test
#sudo iw $connected_card connect 'HTC network'
sudo iwconfig $connected_card essid 'HTC network'
echo "$connected_card is connected"
# connected_card=$WLAN0
echo "$connected_card is getting an ip address"
sudo dhclient $connected_card

#sudo ip addr add 192.168.1.136/24 dev $connected_card
echo "Now trying to ping google.com this might take some time"
sudo ping -c4 google.com #ping command to check the connection

sleep 2
echo "Starting the wireless interface $scanning_card"
sudo ifconfig $scanning_card up
sudo ip link set $scanning_card up
# scanning_card=$WLAN1
ROAMING_THRESHOLD_WLAN1=40/100 # placing a roaming threshold or trigger for handover

ROAMING_THRESHOLD_WLAN0=`awk 'BEGIN{printf("%0.2f", 20/70 )}'`

while [ 1 ]
do
#scanning for access point with better signal

access_point_highest_sig=`sudo iwlist $scanning_card scan | egrep 'ESSID|Quality' | sort -r | grep ESSID | head -1 | cut -f2 -d:`

scanning_card_signal_quality=`sudo iwlist $scanning_card scan | grep 'Quality' | sort -m | head -1 | awk '{print $1}' | cut -f2 -d=`

connected_card_signal_quality=`sudo iwlist $connected_card scan | grep 'Quality' | sort -m | head -1 | awk '{print $1}' | cut -f2 -d=`

scanning_card_signal_quality=`awk 'BEGIN{printf("%0.2f", '$scanning_card_signal_quality' )}'`
connected_card_signal_quality=`awk 'BEGIN{printf("%0.2f", '$connected_card_signal_quality' )}'`

# display access point with better signal and the access point itself
echo "$scanning_card signal quality $scanning_card_signal_quality is scanning"
echo "$connected_card signal quality $connected_card_signal_quality is connected"
echo "Access point returned by wlan1 with highest signal $access_point_highest_sig"
# sleep 3


echo "$scanning_card_signal_quality $ROAMING_THRESHOLD_WLAN0 $connected_card_signal_quality" | awk '{if (($1 > $2) && ($3 < $2)) {'
echo "Starting handover from $connected_card to $scanning_card"
start_handover=$(date +%s.%N)
sudo iwconfig $scanning_card essid 'HTC network'
end_handover=$(date +%s.%N)
time_delay=$(echo "$end_handover - $start_handover" | bc)
echo "Handover time delay is $time_delay nanoseconds"
# sudo dhclient $WLAN0
sudo dhclient $connected_card
# sudo ip addr add 192.168.1.136/24 dev $scanning_card
sudo ping -c4 google.com #ping command to check the connection
echo "line 64"
#sudo ip link set down $connected_card
sudo dhclient -r $connected_card
sudo ip link set up $connected_card
temp=$connected_card
connected_card=$scanning_card
scanning_card=$temp'}'

done
 
Old 04-08-2012, 07:39 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984
why have you posted all of that crap when it's clearly an error in the awk command?

Code:
awk '{if (($1 > $2) && ($3 < $2)) {'
that is an *entire* awk script, and clearly an illegal one, as the is indeed no matching } at the end. It looks like you expect the one about 10 lines later to magically work, but it won't, as it's 10 entire bash commands away.

If sounds like you're trying to use awk to make an "if then else" statement outside of it's own scope or something... very odd. Remove the awk and do it with proper bash instead.

Last edited by acid_kewpie; 04-08-2012 at 07:40 AM.
 
Old 04-08-2012, 10:49 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Useful post questions should include only details relevant to your problem, not just a giant dump of everything you have.

Nobody wants to take the time to read through a mess of text to locate your errors for you, so take some time to cut it down to the section or commands that relate directly to the problem at hand. Who knows, you might discover where you went wrong in the process on your own while you're at it.

Please read How To Ask Questions The Smart Way, for more tips on how to get the most out of help forums like this.

Also, when you post, please use [code][/code] tags around your code and data, to preserve formatting and to improve readability.

Please do not use quote tags, colors, or other fancy formatting.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
AWK/BASH: get nth line from a file by getline feed to actions in a same awk line cristalp Programming 3 11-23-2011 11:38 AM
[SOLVED] call awk from bash script behaves differently to awk from CLI = missing newlines titanium_geek Programming 4 05-26-2011 09:06 PM
[SOLVED] bash awk column to end of file alex1986 Programming 8 09-04-2010 06:04 PM
how to replace line of file with another line using awk in shell script amit_pansuria Programming 3 03-29-2009 09:43 AM
Can not capture no at end of file store it and print it using sed and awk amuthiga Programming 10 11-26-2008 07:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration