#!/bin/bash # Christopher Jones # 06/16/2013 # This Script goes through all available part numbers and gets the cvns using a proxy list and getcvn.py # Dependencies getcvn.py ./proxielist.txt #Intialize variables # Current Part Number File- this file is used to keep track of current state CURPARTNUMFILE="./partnum.txt" # Proxy List PROXIELIST="./proxielist.txt" # CVN Output File OUTFILE="./GM_Partnumbers.txt" # Log File LOGFILE="/var/log/getallcvn-log.txt" # Last Partnumber END=30000000 # Proxies PROXIES=$(cat "$PROXIELIST") Get_Current_Partnumber(){ local FILE=$1 # Get latest partnumber searched if [ ! -f "$FILE" ]; then echo "" >> "$FILE" currentpartNum=9000000 else currentpartNum=$(cat "$FILE") fi echo $currentpartNum } #END GET_CURRENT_PARTNUMBER Pick_Random_Proxy(){ local Proxies=$1 Proxytotal=$(echo "$Proxies" | wc -l) echo "$Proxies" | sed -n $[(RANDOM % $Proxytotal) +1]p } #END GET_PROXIES #MAIN--------------------------------------------------------------------- INDEX=$(Get_Current_Partnumber $CURPARTNUMFILE) # For each Partnumber get cvn and sleep for random time for ((PARTNUM=$INDEX;PARTNUM<=$END;PARTNUM++)); do OUTPUT=3 while [ $OUTPUT -eq 3 ]; do Proxy=$(Pick_Random_Proxy "$PROXIES") echo "$(date) : Getting CVN for $PARTNUM, Using Proxy:$Proxy!" | tee -a $LOGFILE echo -n "$(date) : " >> $LOGFILE OUTPUT=$(python ./getcvn.py -p $PARTNUM -P $Proxy -o $OUTFILE 2>&1 >> $LOGFILE; echo $?) if [ $OUTPUT -eq 3 ]; then echo "$(date) : Proxy failed!, trying $PARTNUM again with a different proxy!" >> $LOGFILE elif [ $OUTPUT -eq 2 ]; then echo "$(date) : No cvn was found for $PARTNUM, moving on.." >> $LOGFILE elif [ $OUTPUT -eq 1 ]; then echo "$(date) : Script failed, moving on.." >> $LOGFILE elif [ $OUTPUT -eq 0 ]; then echo "$(date) : CVN FOUND for $PARTNUM, moving on.." >> $LOGFILE else echo "$(date) : Error in script!, please check!: $OUTPUT" >> $LOGFILE fi done echo $PARTNUM > "$CURPARTNUMFILE" sleep $[( $RANDOM % 10) +1]s done rm "$CURPARTNUMFILE" #EOF