I'm working on a Bash script that is designed to calculate how much IP traffic has passed through a port to determine traffic volume over a given amount of time.
I've currently been able to use the netstat -s command coupled with grep to write to a file the total packets received and I can't figure out how to use these numbers in a script to perform mathematical functions between them.
nistleloy@****:~/Documents> cat tempIP
6643 total packets received
6718 total packets received
7293 total packets received
7785 total packets received
So with these numbers I want to use them in a script that subtracts the first reading from the second and the third reading from the fourth - bearing in mind that these numbers could be any size, any length everytime I run the netstat -s cmd.
Will I have to make each line unique so i can grep out just the actual numbers? (How would I do that with physically modifying the txt file).
Now that I have just the numbers displayed within the file is there anyway I can call upon the numbers in a script so I can perform the workings out on them?
What i'm trying to achieve to get is the difference between the readings:
then call upon them in my script to do the maths - how would I assign the varibles within my script and how do I get these variables into my script?
OR:
is there a way to select line 1 from the file and make it a variable in my script then line 2 etc (remembering that these numbers are random so "greping" will not work).
Now that I have just the numbers displayed within the file is there anyway I can call upon the numbers in a script so I can perform the workings out on them?
What i'm trying to achieve to get is the difference between the readings:
then call upon them in my script to do the maths - how would I assign the varibles within my script and how do I get these variables into my script?
OR:
is there a way to select line 1 from the file and make it a variable in my script then line 2 etc (remembering that these numbers are random so "greping" will not work).
Regards
If you get the numbers by themselves in a file, you can do the below to set them to variables.
Code:
COUNT=0
for num in `cat tmpfile2`
do
COUNT=`expr $COUNT + 1`
eval r${COUNT}=$num
done
echo "$r1 $r2 $r3 $r4"
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
Write a shell script that will take the sum of two random number?
Ex: Random n1 +Random n2 = result
i tries to write it but i had some dufficulties
... (3 Replies)
Hi,
I am new to Unix/ksh script and will like to check how do I retrieve just the count of '258' in the last line in a text file ?
There will be this "TRL" appended with number of count at the last line in a text file .
TRL0000000258
var=`grep 'TRL' $HOME/folder/test.txt | wc -l`
... (12 Replies)
Hi,
I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
I have a text file with hundreds of lines, i wish to run a script and reads a random line to pass it to another command line such as:
for line in `cat file |grep random line`; do echo $line |mail my@example.com ; done
thank you (6 Replies)
Hello,
I need to take a random word from a flat text file with words in it seperated by spaces.
The code I am using, always gives me the first word. Can anyone please shed some light on this. Here's my code.
Thanks
echo table roof ceiling jar computer monitor keyboard carpet >... (5 Replies)
i want to need script..
source.txt
/home/user1/public_html/test3
/home/user90/public_html/test9
.
.
.
/home/user650/public_html/test000
read source.txt and cd /home/user**/public_html/***
and there is 1.txt, 2txt ~~25.txt
and select 6 text files randomly among the... (4 Replies)
Is anyone know some scripts to generate random number without repetition using bash; for example generate 10 different random numbers.
Thanks (8 Replies)
I have a file which contains lots of text (comment field). I would like to parse through the comment field which can be up to 255 characters long and look for anything that seems to resemble, say, a credit card number or customer account number, etc. and replace the numbers with asteriks (*).
... (9 Replies)