LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-27-2006, 12:32 PM   #1
leventis
LQ Newbie
 
Registered: Jan 2002
Posts: 12

Rep: Reputation: 0
Question Random file lines directed to a new file. In script an error. In command line no err


Sorry for the longs subject.. I ment to make it descriptive

By performing the following command on the command prompt no error is received. The job is performed correctly.

cat test1 |while read l ; do echo "0$RANDOM $l" ; done|sort -n -o test1.shi

If I put the following line in a script I receive the following error.

redirection error: cannot duplicate fd: Too many open files

Full script code
Code:
#Sort text file
sort()
{
	sort $filename.on > $filename.on.done
	sort $filename.off > $filename.off.done
	rm -rf $filename.on
	rm -rf $filename.off
	mv $filename.on.done $filename.on
	mv $filename.off.done $filename.off
	rm -rf $filenameBAK
}


if [ $# -lt 1 ]
then
	#call usage function
	usage
fi

#Variables
filename=$1
filenameBAK="$1BAK"
debug="echo"
#debug=":"


cat $filename |
while read line #read each line of the file into variable line
do   

	#randomize text file 
	#ERROR EHRE~~~
	cat test1 |while read l ; do echo "0$RANDOM $l" ; done|sort -n -o test1.shi
	
	
	#Generate random port
	rand=0
	RANGE=65535 #total ports
	FLOOR=1025 # greater than 1024 (eliminating root ports)
	while [ "$rand" -le $FLOOR ]
	do
		rand=$RANDOM
  	let "rand %= $RANGE"  # Scales $number down within $RANGE.
	done
	$debug "Random number between $FLOOR and $RANGE ---  $rand"
	#end of generate random port


	#Split ip from host name to use it
	oldifs="$IFS"

	$debug "input line is :$line:"
      	IFS="${IFS}=" #IFS BEFORE USING!
	set -- $line #use line splited from ip=dns to ip dns ($1 $2)

        ip=$1
        dns=$2
       	
	$debug "IP: $1"
	$debug "DNS: $dns"
        
	IFS="$oldifs"
	#End of splitting ip and dns

	#Search crafted string and execute command
	#Special
	# -p random number
	# -i time (waittime, 20 secs)
	#-s port (source port)
	#--keep
	#./hping2 -c 1 -A -V  -p $rand -i time
	#Send one packet, ACK, Verborse, at random port, every 20 secs, source port 80
	#./hping2 -c 1 -A -V -p $rand -i 20 -s 80 --keep $ip
	# Find: 1 packets tramitted, 1 packets received, 0% packet loss
	
	status="" #ON/OFF
	#hping output is not the statistics.. its the response
	#ACK returns RST flag
	./hping2 -c 1 -A -V -p $rand -i 20 -s 80 --keep $ip  |grep "flags=R"

	# $? stands for last commands exit status
	# If its 0 then grep was successfull and host is alive :)
	if [ "$?" -eq "0" ]; then
	
		status="ON"
		echo "$status $ip=$dns" >> $filename.on
	else
		status="OFF"
		echo "$status $ip=$dns" >> $filename.off
	fi
	$debug "Status: $status"
	#End of search crafted string

	sort #call sort funtion
	
done
Thanks in advance!
 
Old 09-28-2006, 07:16 AM   #2
leventis
LQ Newbie
 
Registered: Jan 2002
Posts: 12

Original Poster
Rep: Reputation: 0
Stupid me!

I had created a function called sort. So the script instead of calling the sort command would call the sort function.

 
  


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
Replace line in file with two lines?! Possible? eur0dad Linux - General 2 09-07-2006 02:15 PM
Printing random lines of a file jrdioko Linux - Software 3 07-20-2006 09:00 AM
Read random line from a file in C introuble Programming 6 06-19-2006 09:37 AM
command or shell script to print line range from file minil Programming 3 12-28-2005 08:05 AM
nfs a file shares ok via file mngr but not command line. Suse 9.1 acummings Linux - Networking 2 10-09-2004 02:23 PM


All times are GMT -5. The time now is 12:52 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration