LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-24-2015, 05:50 AM   #1
Ed1952
LQ Newbie
 
Registered: Dec 2003
Posts: 12

Rep: Reputation: 0
Shell script to cause wifi scan get "unexpected end of file" message


I need to get my wifi scanning while I run Wireshark in Ubuntu. I tried some of the scripts that I found on the internet, but they did not run correctly. So, I decided to write my own very simple script. I know there are more elegant ways to do this, but I decided to keep things as simple as possible, after verifying that if I enter, for example, sudo iwconfig wlan0 channel 1 that the wifi modem tunes to channel 1. So, what I want to do is to continuously scan through the a and b channels while running Wireshark. I want it to dwell on each channel for 0.1 seconds. But, every time I try to run this shell script, I get an "unexpected end of file" error. What is wrong? I suspect it is something simple and stupid, but I can't spot it.
#!/bin/bash
while true
do
iwconfig mon0 channel 1
sleep .1
iwconfig mon0 channel 2
sleep .1
iwconfig mon0 channel 3
sleep .1
iwconfig mon0 channel 4
sleep .1
iwconfig mon0 channel 5
sleep .1
iwconfig mon0 channel 6
sleep .1
iwconfig mon0 channel 7
sleep .1
iwconfig mon0 channel 8
sleep .1
iwconfig mon0 channel 9
sleep .1
iwconfig mon0 channel 10
sleep .1
iwconfig mon0 channel 11
sleep .1
iwconfig mon0 channel 36
sleep .1
iwconfig mon0 channel 40
sleep .1
iwconfig mon0 channel 44
sleep .1
iwconfig mon0 channel 48
sleep .1
iwconfig mon0 channel 52
sleep .1
iwconfig mon0 channel 56
sleep .1
iwconfig mon0 channel 60
sleep .1
iwconfig mon0 channel 64
sleep .1
iwconfig mon0 channel 149
sleep .1
iwconfig mon0 channel 153
sleep .1
iwconfig mon0 channel 157
sleep .1
iwconfig mon0 channel 161
sleep .1
done
 
Old 11-24-2015, 05:58 AM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
Nothing wrong with the bash syntax, maybe you have odd hidden characters? did you use a windows text editor to make the script if so you will have windows style line endings which would produce that or a similar error
 
Old 11-24-2015, 06:08 AM   #3
Ed1952
LQ Newbie
 
Registered: Dec 2003
Posts: 12

Original Poster
Rep: Reputation: 0
I did use the windows text editor to create the script, although I did some modifications in Gedit. How do I find and eliminate the extra characters? As I said, latest version edited and saved with Gedit.
 
Old 11-24-2015, 07:19 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,789

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
usually that means \r\n at the end of line which may cause such kind of errors.
use od -xv filename for example to check it
 
Old 11-24-2015, 07:25 AM   #5
Ed1952
LQ Newbie
 
Registered: Dec 2003
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks. That was the problem. I ran dos2unix on the file and it works now.
 
Old 11-27-2015, 09:39 AM   #6
debguy
Member
 
Registered: Oct 2014
Location: U.S.A.
Distribution: mixed, mostly debian slackare today
Posts: 207

Rep: Reputation: 19
> I tried some of the scripts that I found on the internet, but they did not run correctly.

why not? i'm sure the authors hoped what they spent time writing and releasing could be used by others.

so you tried several and they were damaged? very bad. please say what you think the cause of damage is!
 
  


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
[SOLVED] Script returning with error "syntax error: unexpected end of file" n_raghuvanshi Linux - Software 4 08-25-2013 08:49 AM
[SOLVED] "Unexpected End of File" message on LXTerminal while trying to unzip a .tar.gz file pioneermtb Debian 2 12-22-2012 07:55 PM
[SOLVED] Shell Scripting "syntax error : unexpected end of file" roxie600 Programming 12 04-30-2010 12:18 AM
Backup Script error "line 31: syntax error: unexpected end of file" eswanepoel General 7 12-07-2007 09:28 AM
bash "unexpected end of file" script error Runge_Kutta Linux - General 6 05-23-2007 03:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:53 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