Advertisement
Guest User

Untitled

a guest
May 6th, 2012
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.32 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. self=$0;
  4. user=$1;
  5.  
  6. logfile='/tmp/kwtracker.log'
  7.  
  8. curl_bin=$(whereis curl | awk '{print $2}')
  9. grep_bin=$(whereis grep | awk '{print $2}')
  10. sed_bin=$(whereis sed | awk '{print $2}')
  11.  
  12. function Usage {
  13.         echo "$self <username>";
  14.         exit 0
  15. }
  16.  
  17. function Log {
  18.         echo "$(date '+%F %T') $self[$$]: dumping stats for $user. $1" >> $logfile
  19. }
  20.  
  21. if [[ ! -x $curl_bin || ! -x $grep_bin || ! -x $sed_bin ]]; then
  22.         echo "curl, grep, or sed not found. "
  23.         exit 0
  24. fi
  25.  
  26. if [[ ! -w $logfile ]]; then
  27.         touch $logfile
  28. fi
  29.  
  30. if [[ $user == '' ]]; then
  31.         Usage
  32. fi
  33.  
  34. stat_data=$($curl_bin --silent http://www.karmawhores.net/user/$user | tr "\n" "\t" | $grep_bin -E -o "<div class=\"stat_set\">.*reddit Registration Date" | $sed_bin -e 's/\t/ /g' -e 's/>\s\+</></g' -e 's/"stat_box"/<DELIM>\n/g' | $grep_bin 'div><div class=<DELIM>')
  35.  
  36. stat_string=$(echo "$stat_data" | while read stat_line; do
  37.         stat_name=$(echo "$stat_line" | $grep_bin -E -o "\"stat_title\">[^<]+</div>" | $sed_bin -e 's/"stat_title">//g' -e 's/<\/div>//g')
  38.         stat_value=$(echo "$stat_line" | $grep_bin -E -o "\"stat_num\">[^<]+</div>" | $sed_bin -e 's/"stat_num">//g' -e 's/<\/div>//g' -e 's/#//g')
  39.        
  40.         echo -n "$stat_string$(echo -n "$stat_name = $stat_value|")"
  41. done)
  42.  
  43. Log "$stat_string"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement