Find the answer to your Linux question:
Results 1 to 4 of 4
Im trying to make a script that updates the status of a list of proxy servers automatically. The list of proxys is in a csv file that looks like this ...
  1. #1
    Just Joined!
    Join Date
    Mar 2009
    Posts
    11

    awk bash script help please

    Im trying to make a script that updates the status of a list of proxy servers automatically.
    The list of proxys is in a csv file that looks like this called proxylist.csv
    ,ID,ADDRESS,PORT,TYPE,COUNTRY,LAST TEST,SPEED,RELIABILITY
    1,85.17.92.24,1080,Socks5,Netherlands,3/25/2009,<img src=/wp-content/statusbar/statusbar.php?rating=100 alt=Speed 100/100 />,<img src=/wp-content/statusbar/statusbar.php?rating=100 alt=Speed 100/100 />,
    2,71.74.180.178,7437,Socks5,United States,3/25/2009,<img src=/wp-content/statusbar/statusbar.php?rating=100 alt=Speed 100/100 />,<img src=/wp-content/statusbar/statusbar.php?rating=100 alt=Speed 100/100 />,
    3,218.28.25.55,1080,Socks4,China,3/25/2009,<img src=/wp-content/statusbar/statusbar.php?rating=90 alt=Speed 90/100 />,<img src=/wp-content/statusbar/statusbar.php?rating=100 alt=Speed 100/100 />,
    Im trying to ping each host then take the response and input it into the proxylist file where 100/100 and 100/100 are in fields 7 and 8 this is what I have so far

    #!/bin/sh

    for IP in $(cut -d ',' -f2 /opt/lampp/htdocs/wordpress/wp-content/files/proxylist.csv|gre$
    ping $IP -c10 > test.txt //pings host
    grep ttl test.txt|cut -d " " -f7|cut -d "=" -f2 > $IP'times.txt'
    // cuts only the ping response times//
    grep received test.txt|cut -d " " -f4 > $IP'packets.txt'
    // cuts only the packets received number//
    rm test.txt
    value=0
    while read var
    do
    value=$(echo "$value + $var" |bc)
    done < $IP'times.txt'
    a=$value
    b=$(echo "$a/10" |bc)
    //b= the average response time//
    c=$(cat $IP'packets.txt')
    // c=the packets received//
    rm $IP'packets.txt'
    rm $IP'times.txt'
    if [ "$b" -ge "2000" ];then
    b=0
    elif [ "$b" -ge "1800" ];then
    b=10
    elif [ "$b" -ge "1600" ];then
    b=20
    elif [ "$b" -ge "1400" ];then
    b=30
    elif [ "$b" -ge "1200" ];then
    b=40
    elif [ "$b" -ge "1000" ];then
    b=50
    elif [ "$b" -ge "800" ];then
    b=60
    elif [ "$b" -ge "600" ];then
    b=70
    elif [ "$b" -ge "400" ];then
    b=80
    elif [ "$b" -ge "200" ];then
    b=90
    elif [ "$b" -ge "1" ];then
    b=100
    else
    b=0
    fi
    //takes the average response time and assigns it a number from 1-100 100 being fast 1 being slow//
    if [ "$c" -eq "10" ];then
    c=100
    elif [ "$c" -eq "9" ];then
    c=90
    elif [ "$c" -eq "8" ];then
    c=80
    elif [ "$c" -eq "7" ];then
    c=70
    elif [ "$c" -eq "6" ];then
    c=60
    elif [ "$c" -eq "5" ];then
    c=50
    elif [ "$c" -eq "4" ];then
    c=40
    elif [ "$c" -eq "3" ];then
    c=30
    elif [ "$c" -eq "2" ];then
    c=20
    elif [ "$c" -eq "1" ];then
    c=10
    elif [ "$c" -eq "0" ];then
    c=0
    fi
    //takes the packets received and assigns it a number from 1-100 100 being all packets received 0 being no packets received//

    echo $IP,$b,$c
    //test to display and check the values $IP is the ipaddress $b is response time from 1-100 and $c is packets received from 1-100//
    //this is where im getting stuck i need something like if $IP matches the ip address in field 2 of the csv file then replace
    < img src=/wp-content/statusbar/statusbar.php?rating=100/100 in filed 7 with
    "<img src=/wp-content/statusbar/statusbar.php?rating="$b”/100”;
    and replace $8 from
    "<img src=/wp-content/statusbar/statusbar.php?rating=100/100 with
    "<img src=/wp-content/statusbar/statusbar.php?rating="$c”/100”;

    This is what I have tried and im having trouble getting it to work //


    awk -F, '
    BEGIN{OFS=","}
    {if ($2 = $IP)
    $7 = "<img src=/wp-content/statusbar/statusbar.php?rating="$b”/100”;
    $8 = "<img src=/wp-content/statusbar/statusbar.php?rating="$c”/100”;
    print}' proxylist.csv > proxylist2.csv
    done

  2. #2
    Just Joined!
    Join Date
    Mar 2009
    Posts
    11

    I got a lil further

    Well I was able to replace columns or fields 7 but not 8 with this line the problem is it does it on every line not just the line that mates the ip address in filed 2 {if ($2 = $IP)

    Oh and i replaced the vale of $b is now $speed and $c is now $life

    awk -F, '
    BEGIN{OFS=","}
    {if ($2 = $IP)
    $7 = "<img src=/wp-content/statusbar/statusbar.php?rating='$speed' alt=Speed '$speed'/100 />";
    $8 = "<img src=/wp-content/statusbar/statusbar.php?rating='$life' alt=Speed '$life'/100 />";
    print}' proxylist.csv > proxylist2.csv
    done

  3. #3
    Just Joined!
    Join Date
    Mar 2009
    Posts
    11

    still trying

    $2 == $IP replaces all $8
    $2 == '$IP' replaces all $8
    $2 = '$IP' replaces all $2 with $IP and all $7 and $8
    $2 = $IP replaces only line one $7 and $8 and adds an extra colum of numbers to all rows
    $2 -eq '$IP' replaces all $7 and $8
    $2 -eq $IP replaces all $7 and $8
    $2 =={$IP} error
    $2 =={'$IP'} error
    $2 == 'IP' replaces all $8
    $2 -o '$IP' replaces all $8

    Grrrrrrr

  4. #4
    Just Joined!
    Join Date
    Mar 2009
    Posts
    11

    I fixed it

    Finally got it work this is how it need to formatted


    awk '
    BEGIN{FS=",";OFS=","}
    /'$IP'/ {$6 = "'$time'"
    $7 = "<img src=/wp-content/statusbar/statusbar.php?rating='$speed' alt=Speed '$speed'/100 />"
    $8 = "<img src=/wp-content/statusbar/statusbar.php?rating='$life' alt=Speed '$life'/100 />"
    print}' /opt/lampp/htdocs/wordpress/wp-content/files/proxylist.csv >> proxylist2.csv

    By the way this hand for monitory the health of a network or servers around the world as well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...