mirror of
				https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
				synced 2025-10-30 18:27:53 +00:00 
			
		
		
		
	lf_curl script written more correctly, might not work as intended
This commit is contained in:
		
							
								
								
									
										95
									
								
								lf_curl.sh
									
									
									
									
									
								
							
							
						
						
									
										95
									
								
								lf_curl.sh
									
									
									
									
									
								
							| @@ -1,7 +1,14 @@ | |||||||
| #!/bin/bash | #!/bin/bash | ||||||
| [ -f /home/lanforge/lanforge.profile ] && . /home/lanforge/lanforge.profile | if [ -f /home/lanforge/lanforge.profile ]; then | ||||||
| CURL=`which curl`; |    . /home/lanforge/lanforge.profile | ||||||
|  | else | ||||||
|  |    echo "/home/lanforge/lanforge.profile not found, bye." | ||||||
|  |    exit 1 | ||||||
|  | fi | ||||||
|  | CURL=`which curl` | ||||||
|  | IP=`which ip` | ||||||
| #echo $CURL; | #echo $CURL; | ||||||
|  | [ -f lib_vrf.bash ] && . ./lib_vrf.bash | ||||||
|  |  | ||||||
| SOURCE_IP="" | SOURCE_IP="" | ||||||
| SOURCE_PORT="" | SOURCE_PORT="" | ||||||
| @@ -11,21 +18,22 @@ NUM_LOOPS=1 | |||||||
|  |  | ||||||
| help="$0 options: | help="$0 options: | ||||||
|       -d {destination_url} |       -d {destination_url} | ||||||
|       -h this help |       -h # this help | ||||||
|       -i {source ip} |       -i {source ip} | ||||||
|       -n {number of times, 0 = infinite} |       -n {number of times, 0 = infinite} | ||||||
|       -o {output file prefix, /dev/null is default} |       -o {output file prefix, /dev/null is default} | ||||||
|       -p {source port} |       -p {source port} | ||||||
|  |       -v # verbose curl option -# | ||||||
| E.G.: | E.G.: | ||||||
|    $0 -i 10.0.0.1 -p eth1 -o /tmp/output -d http://example.com/ |    $0 -i 10.0.0.1 -p eth1 -o /tmp/output -d http://example.com/ | ||||||
| becomes | becomes | ||||||
|    curl -sqLk --interface 10.0.0.1 -o /tmp/output_eth1 http://example.com/ |    curl -sq. ~Lk --interface 10.0.0.1 -o /tmp/output_eth1 http://example.com/ | ||||||
|  |  | ||||||
| Best if used from lf_generic_ping.pl to construct commands referencing this script: | Best if used from lf_generic_ping.pl to construct commands referencing this script: | ||||||
|    ./lf_generic_ping.pl --mgr cholla-f19 -r 2 -n curl_ex_ --match 'eth2#' --cmd 'lf_curl.sh -o /tmp/curl_%p.out -i %i -d %d -p %p' --dest http://localhost/ |    ./lf_generic_ping.pl --mgr cholla-f19 -r 2 -n curl_ex_ --match 'eth2#' --cmd 'lf_curl.sh -o /tmp/curl_%p.out -i %i -d %d -p %p' --dest http://localhost/ | ||||||
| " | " | ||||||
|  | LFCURL='' | ||||||
| while getopts ":d:hi:n:o:p:" OPT ; do | while getopts ":d:vhi:n:o:p:" OPT ; do | ||||||
|    #echo "OPT[$OPT] OPTARG[$OPTARG]" |    #echo "OPT[$OPT] OPTARG[$OPTARG]" | ||||||
|    case $OPT in |    case $OPT in | ||||||
|    h) |    h) | ||||||
| @@ -36,10 +44,9 @@ while getopts ":d:hi:n:o:p:" OPT ; do | |||||||
|       DEST_HOST="$OPTARG" |       DEST_HOST="$OPTARG" | ||||||
|       ;; |       ;; | ||||||
|    i) |    i) | ||||||
|       if [[ $CURL = ~/local/bin/curl ]]; then |       PORT_IP="$OPTARG" | ||||||
|          SOURCE_IP="--dns-ipv4-addr $OPTARG --interface $OPTARG" |       if [[ $CURL = ~/local/bin/curl ]] || [[ $CURL = /home/lanforge/local/bin/curl ]]; then | ||||||
|       else |          LFCURL=1 | ||||||
|          SOURCE_IP="--interface $OPTARG" |  | ||||||
|       fi |       fi | ||||||
|       ;; |       ;; | ||||||
|    n) |    n) | ||||||
| @@ -49,8 +56,12 @@ while getopts ":d:hi:n:o:p:" OPT ; do | |||||||
|       OUT_FILE="$OPTARG" |       OUT_FILE="$OPTARG" | ||||||
|       ;; |       ;; | ||||||
|    p) |    p) | ||||||
|  |       PORT="$OPTARG" | ||||||
|       SOURCE_PORT="--interface $OPTARG" |       SOURCE_PORT="--interface $OPTARG" | ||||||
|       ;; |       ;; | ||||||
|  |    v) | ||||||
|  |       PROGRESS='-#' | ||||||
|  |       ;; | ||||||
|    *) |    *) | ||||||
|       echo "Unknown option [$OPT] [$OPTARG]" |       echo "Unknown option [$OPT] [$OPTARG]" | ||||||
|       ;; |       ;; | ||||||
| @@ -64,27 +75,67 @@ fi | |||||||
|  |  | ||||||
| if [[ x$OUT_FILE != x/dev/null ]] && [[ x$SOURCE_PORT != x ]] ; then | if [[ x$OUT_FILE != x/dev/null ]] && [[ x$SOURCE_PORT != x ]] ; then | ||||||
|    OUT_FILE="-o ${OUT_FILE}_${SOURCE_PORT}" |    OUT_FILE="-o ${OUT_FILE}_${SOURCE_PORT}" | ||||||
|  | elif [[ $OUT_FILE = /dev/null ]]; then | ||||||
|  |    OUT_FILE="-o ${OUT_FILE}" | ||||||
| fi | fi | ||||||
|  |  | ||||||
|  | VRF='' | ||||||
| NUM_GOOD=0 | NUM_GOOD=0 | ||||||
|  | LB='#' | ||||||
|  | L_SOURCE_PORT="$PORT" | ||||||
|  | if [[ $PORT = *$LB* ]] && [[ $PORT != *@* ]]; then | ||||||
|  |    L_SOURCE_PORT="${PORT}@${PORT//#*/}" | ||||||
|  | fi | ||||||
|  | if [[ ${#IFNAMES[@]} -lt 1 ]]; then | ||||||
|  |    [[ x$PROGRESS != x ]] && echo "NO VRF PORTS: ${#IFNAMES[@]}" | ||||||
|  | else | ||||||
|  |    [[ x$PROGRESS != x ]] && echo "SOME VRF PORTS: ${#IFNAMES[@]}" | ||||||
|  |    if [[ x${IFNAMES[$L_SOURCE_PORT]} = x ]]; then | ||||||
|  |       [[ x$PROGRESS != x ]] && echo "No vrf port detected for $L_SOURCE_PORT" | ||||||
|  |    else | ||||||
|  |       [[ x$PROGRESS != x ]] && echo "VRF port: ${IFNAMES[$L_SOURCE_PORT]}" | ||||||
|  |       VRF=1 | ||||||
|  |    fi | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | if [[ $VRF = 1 ]]; then | ||||||
|  |    SOURCE_IP='' | ||||||
|  | elif [[ $LFCURL = 1 ]]; then | ||||||
|  |    SOURCE_IP="--dns-ipv4-addr $OPTARG --interface $OPTARG" | ||||||
|  | else | ||||||
|  |    SOURCE_IP="--interface $OPTARG" | ||||||
|  | fi | ||||||
|  |  | ||||||
|  |  | ||||||
|  | STD_O="/tmp/lf_curl_so.$$" | ||||||
|  | if [[ x$PROGRESS = x ]]; then | ||||||
|  |    VERB="-s" | ||||||
|  |    STD_E="/tmp/lf_curl_se.$$" | ||||||
|  | else | ||||||
|  |    VERB="" | ||||||
|  |    STD_E="" | ||||||
|  | fi | ||||||
|  | CCMD="$CURL $VERB -Lk --connect-timeout 2 --max-time 10 $PROGRESS \ | ||||||
|  | -D /tmp/lf_curl_h.$$ $OUT_FILE $SOURCE_IP $DEST_HOST" | ||||||
|  |  | ||||||
|  | if [[ x$VRF != x ]]; then | ||||||
|  |    CCMD="$IP vrf exec ${IFNAMES[$L_SOURCE_PORT]} $CCMD" | ||||||
|  | fi | ||||||
|  |  | ||||||
| for N in `seq 1 $NUM_LOOPS`; do | for N in `seq 1 $NUM_LOOPS`; do | ||||||
|    $CURL -sqLk --connect-timeout 1 \ |    if [[ x$PROGRESS = x ]]; then | ||||||
|       --max-time 10 \ |       $CCMD > $STD_O &> $STD_E | ||||||
|       -D /tmp/lf_curl_h.$$ \ |    else | ||||||
|       $OUT_FILE \ |       echo "Running $CCMD" | ||||||
|       $SOURCE_IP \ |       $CCMD | ||||||
|       $DEST_HOST \ |    fi | ||||||
|       > /tmp/lf_curl_so.$$ \ |  | ||||||
|       2> /tmp/lf_curl_se.$$ |  | ||||||
|  |  | ||||||
|    if [[ $? > 0 ]]; then |    if [[ $? > 0 ]]; then | ||||||
|       echo "Failed $DEST_HOST" |       echo "Failed $DEST_HOST" | ||||||
|       head -1 /tmp/lf_curl_se.$$ |       [ -f /tmp/lf_curl_se.$$ ] && head -1 /tmp/lf_curl_se.$$ | ||||||
|    else |    else | ||||||
|       NUM_GOOD=$(( $NUM_GOOD +1)) |       NUM_GOOD=$(( $NUM_GOOD +1)) | ||||||
|       head -1 /tmp/lf_curl_so.$$ |       [ -f /tmp/lf_curl_so.$$ ] && head -1 /tmp/lf_curl_so.$$ | ||||||
|       head -1 /tmp/lf_curl_h.$$ |       [ -f /tmp/lf_curl_h.$$ ] && head -1 /tmp/lf_curl_h.$$ | ||||||
|    fi |    fi | ||||||
|    sleep 1 |    sleep 1 | ||||||
| done | done | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jed Reynolds
					Jed Reynolds