I am pretty new at this, so while it might seem like a very simple request, I'm not at the point where I can write it myself.

I want to schedule a script to run each day, capturing the logins I have had for the previous day. I already wrote a script that scours the logs of my app and gives me the date, the total number of logins and the number of unique users. I would like to have a script that parses the two numbers into two strings that I can use to insert into a Google Charts URL for a WGET.

#!/bin/bash# Make a human-readable version of the first argument passed to the script (./script.sh <argument 1>)file=$1# reset the counteri=0# Do a line by line loop of the file supplied in argument 1 (or as it is now known, $file)# The IFS variable tells us what we should look for to create an itteration inside for(1)# old_IFS is just a way to reset the IFS when we're done :)old_IFS=$IFSIFS=""# The for(1) loop will read the $file and sort it according to column 1, the date in your supplied example.for i in $(cat $file | sort -t',' -k1,1); do # This adds the second column to an array named "array1" array1[$i]=$(echo $i | cut -d',' -f2) # This adds the third column to an array named "array2" array2[$i]=$(echo $i | cut -d',' -f3) # Increment the elemental counter :) ((i++))doneIFS=$old_IFS# Echo the entire array (and since it's space separated we replace all spaces with commas)total_logins=$(echo ${array1[*]} | replace " " ",")total_unique=$(echo ${array2[*]} | replace " " ",")

echo "total_logins=$total_logins"echo "total_unique=$total_unique"

Something like this might give you a clue on how to do it This isn't very well tested... i don't have a proper linux bash shell around here at the moment.

The script as it is now (i copied it flat out and did the same with your example) creates 2 variables at the end.$total_logins$total_unique

These 2 are filled with a comma-separated list of the second column's data (the one you designated as total logins) and the third column's data (total unique).Then it just echo's it as a proof of concept.

Actually, I didn't get a chance to read the comments. I was surfing on my iPhone this morning to see if there were any replies to my post. The iPhone doesn't render the code field properly so I only saw about 4 lines.

# Do a line by line loop of the file supplied in argument 1 (or as it is now known, $file)# The IFS variable tells us what we should look for to create an itteration inside for(1)# old_IFS is just a way to reset the IFS when we're done :)old_IFS=$IFSIFS=""# Sort the total and unique logins for i in $file; do # This adds the second column to an array named "array1" array1[$i]=$(echo $i | cut -d',' -f2) # This adds the third column to an array named "array2" array2[$i]=$(echo $i | cut -d',' -f3) # Increment the elemental counter :) ((i++))doneIFS=$old_IFS

Okay, ran into a bit of a snag. The script worked great until the other day. Then I started getting the following error:

Code:

line 53: 2010-01-08: value too great for base (error token is "08")

Line 53 is part of the following:

Code:

50 # The for(1) loop will read the $file and sort it according to column 1, the date in your supplied example. 51 for i in $MYFILE; do 52 # This adds the second column to an array named "array1" 53 array1[$i]=$(echo $i | cut -d',' -f2) 54 # This adds the third column to an array named "array2" 55 array2[$i]=$(echo $i | cut -d',' -f3) 56 # Increment the elemental counter :) 57 ((i++)) 58 done 59 IFS=$old_IFS

I get the feeling that it is because the 08 in the date is being interpreted as an octal. I can't change the way the date is being stored, as it is an enterprise application I don't control the configuration of. Is there a way I can get the script to interpret the number as base-10 instead?

I already wrote a script that scours the logs of my app and gives me the date, the total number of logins and the number of unique users. I would like to have a script that parses the two numbers into two strings that I can use to insert into a Google Charts URL for a WGET.

Hi, that sounds like fun...

It sounds like something I would write as a function in the larger problem. Can I see the script that gets the stats?

Who is online

Users browsing this forum: Google [Bot] and 17 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum