LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 10-13-2015, 03:11 PM   #31
jzoudavy
Member
 
Registered: Apr 2012
Distribution: Ubuntu, SUSE, Redhat
Posts: 180

Original Poster
Rep: Reputation: Disabled

It works, but I still get these weird operand errors and it still outputs a "total" message at the end.

Code:
./ftp_analyzer_grail.sh
Oct 7 13 total 5867354816 bytes
Oct 6 09 total 2340897 bytes
./ftp_analyzer_grail.sh: line 39: DL_SIZE +=  : syntax error: operand expected (error token is "+=  ")
./ftp_analyzer_grail.sh: line 40: DL_RATE +=  : syntax error: operand expected (error token is "+=  ")
   total 0 bytes
 
Old 10-13-2015, 03:40 PM   #32
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,246

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
I think you must have blank lines in your input file, as the errors are saying that there is nothing to add to our variables and hence the zero total at the end.
Try throwing this in as the first line inside the while loop:
Code:
[[ "$line" ]] || continue
I thought I would also an awk version I threw together as well:
Code:
#!/usr/bin/awk -f

{
  month = $1
  day = $2
  hour = $3
  rate = $6

  mon_sum[month] += rate
  day_sum[month][day] += rate
  hour_sum[month][day][hour] += rate
}

END{
  for( m in mon_sum)
  {
    print "Totals for the month of " m ":" 

    for( d in day_sum[m] )
    {   
      print " Hourly totals for day " d ":" 

      for( h in hour_sum[m][d] )
        print "  Hour :- " h " has a hourly sum of :- "hour_sum[m][d][h]

      print " Daily total is :- " day_sum[m][d]
    }   

    print "Monthly total is :- " mon_sum[m]
  }
}
You run this like so:
Code:
./script.awk input_file
 
Old 10-13-2015, 03:59 PM   #33
jzoudavy
Member
 
Registered: Apr 2012
Distribution: Ubuntu, SUSE, Redhat
Posts: 180

Original Poster
Rep: Reputation: Disabled
what would have been your perfered way to tackle this problem?
 
Old 10-13-2015, 06:14 PM   #34
jzoudavy
Member
 
Registered: Apr 2012
Distribution: Ubuntu, SUSE, Redhat
Posts: 180

Original Poster
Rep: Reputation: Disabled
Hi grail

Just want to say thank you for all the time and effort you have put in for helping me out with this. I thought I would share the final complete solution.

Code:
for use with vsftpd, enable dual mode logging, 

cd /var/log
awk '$10 ~/DOWNLOAD/ {print $2,$3,$4,$14,$15,$16}' vsftpd.log* > simplified.vsftpd.log
sed -i 's/:/ /g' simplified.vsftpd.log
sed -i 's/Kbyte/ Kbyte/g' simplified.vsftpd.log
sed -i 's/\./ /g' simplified.vsftpd.log
./ftp_analyzer.sh > ftp_util.txt
 
Old 10-14-2015, 05:49 AM   #35
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,246

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Well the obvious comment would be that all the awk and seds could be completed inside the script
 
Old 10-14-2015, 10:18 AM   #36
jzoudavy
Member
 
Registered: Apr 2012
Distribution: Ubuntu, SUSE, Redhat
Posts: 180

Original Poster
Rep: Reputation: Disabled
Is there a way to put "./ftp_analyzer.sh > ftp_util.txt" inside the script as well?
 
Old 10-14-2015, 10:38 AM   #37
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,246

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Yes, just setup the redirection to the file at the start of the script and all output will go there instead
 
  


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
parse file with awk and sum totals master-of-puppets Programming 20 09-30-2014 02:06 AM
Help needed for using awk to parse a file to make array for bash script tallmtt Programming 12 04-14-2012 02:16 PM
bash: use file as input into array, parse out other variables from array using awk beeblequix Linux - General 2 11-20-2009 11:07 AM
file time stamp is wrong with ssh file transfer cy163 Linux - Newbie 8 05-18-2008 02:40 AM
ssimple shell script to parse a file ~sed or awk stevie_velvet Programming 7 07-14-2006 04:41 AM


All times are GMT -5. The time now is 10:55 AM.

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