LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-01-2015, 10:12 AM   #1
jsf1337
LQ Newbie
 
Registered: Mar 2015
Location: Leeds UK
Distribution: linux kali
Posts: 2

Rep: Reputation: Disabled
Question why wont my code work, " syntaX error: unexpected end of file"


i have been trying to get this peice of code to work but i cant seem to get it to work.
im just starting out coding and kinda poking around in the dark to get this resolved, any help would be much appriciated, thankyou


Quote:
#!/bin/bash

echo "Would you like to scan using nmap or hping?"

read scanner

if "$scanner" = "nmap" : then

echo "Enter the starting IP address :"

read FirstIP

echo "Enter the last IP address :"

read LastIP

echo "Enter the port number you want to scan for :"

read port

nmap -sT $FirstIP-$LastIP -p $port -oG web
cat web | grep open > web1
cat web1 | cut -f2 -d ":" | cut -f1 -d "(" > web2
cat web2


elit



echo "Which IP address would you like to scan?"

read IPaddress

echo echo "What port would you like to scan for ?"

read hpingport

echo "How many packets would you like to send?"

read packets

hping3 -c $packets $IPaddress -p $hpingport > hpingscan

cat hpingscan
thankyou for any help
 
Old 03-01-2015, 10:36 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Depends on what is happening...


The only odd looking part is
Code:
cat web2


elit
Here cat is going to output whatever is in the file "web2" in the working directory. Then there is whatever "elit" does as it is being treated as an executable.
 
1 members found this post helpful.
Old 03-01-2015, 10:44 AM   #3
jsf1337
LQ Newbie
 
Registered: Mar 2015
Location: Leeds UK
Distribution: linux kali
Posts: 2

Original Poster
Rep: Reputation: Disabled
still trying

i forgot to change elit back to else before i posted does look any better?
but when i do run it, it just says unpecxted end to file, do you need to close "if" statements with "fi"?


Quote:
#!/bin/bash

echo "Would you like to scan using nmap or hping?"

read scanner

if "$scanner" = "nmap" : then

echo "Enter the starting IP address :"

read FirstIP

echo "Enter the last IP address :"

read LastIP

echo "Enter the port number you want to scan for :"

read port

nmap -sT $FirstIP-$LastIP -p $port -oG web
cat web | grep open > web1
cat web1 | cut -f2 -d ":" | cut -f1 -d "(" > web2
cat web2


else



echo "Which IP address would you like to scan?"

read IPaddress

echo echo "What port would you like to scan for ?"

read hpingport

echo "How many packets would you like to send?"

read packets

hping3 -c $packets $IPaddress -p $hpingport > hpingscan

cat hpingscan
 
Old 03-01-2015, 10:59 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
Quote:
do you need to close "if" statements with "fi"?
Yes

Try placing set -xv at the start of the script, specifically the second line, as this should help you pin point where you have errors.

Also, if learning, try commenting out every line but the first and working your way down ... you will soon find which lines cause you issues.
 
1 members found this post helpful.
Old 03-01-2015, 10:59 AM   #5
elija
Member
 
Registered: Jul 2008
Location: The garden of England. Technically, the compost heap.
Distribution: Mint Xfce and #! (now Debian)
Posts: 51

Rep: Reputation: 21
Quote:
Originally Posted by jsf1337 View Post
do you need to close "if" statements with "fi"?
Yes. You may also need to change if "$scanner" = "nmap" : then to if [ "$scanner" = "nmap" ] : then
 
1 members found this post helpful.
Old 03-01-2015, 12:23 PM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
If that is supposed to be "else" then there is a missing "fi" somewhere.

The way the shell works is to read lines into a buffer until it meets the nested structures...

So loops must be terminated, as blocks of commands must also be terminated (either by "fi" or else, but the else starts another block.

And blocks that contain other blocks must also be suitably terminated.
 
1 members found this post helpful.
  


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
PHP Parse error: syntax error, unexpected end of file in Command line code on line 1 pizzipie Programming 8 12-11-2014 01:49 PM
[SOLVED] Script returning with error "syntax error: unexpected end of file" n_raghuvanshi Linux - Software 4 08-25-2013 09:49 AM
[SOLVED] Shell Scripting "syntax error : unexpected end of file" roxie600 Programming 12 04-30-2010 01:18 AM
Backup Script error "line 31: syntax error: unexpected end of file" eswanepoel General 7 12-07-2007 10:28 AM
bash "unexpected end of file" script error Runge_Kutta Linux - General 6 05-23-2007 04:36 PM


All times are GMT -5. The time now is 04:14 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration