Sponsored Content
Top Forums Shell Programming and Scripting Help with a script for proxy traffic Post 303020001 by Katkota on Wednesday 11th of July 2018 09:51:45 PM
Old 07-11-2018
Help with a script for proxy traffic

Hello folks; I'm trying to write a script to test our proxy servers to see if they're passing traffic and i need help please. I wrote this code below to implement "httpie" tool but still having issues. Can someone please take a look and let me know what's wrong with this code? The code is supposed to check all the proxy IP addresses to make sure all IPs are passing traffic and if each proxy returns 200 then the code should exit but if we have an issue, the code should then send me an email saying the specific IP address returned this specific error.
The script runs fine but if any of the Proxys not passing traffic, the script sends an email but it does not tell me which IP failed. Any idea how i make it return the IP address that didn't pass traffic??

Any help with that would be greatly appreciated?

Code:
#!/bin/bash
proxy_targets="http://10.1.1.4:3128 http://10.1.1.5:3128 http://10.1.1.6:3128"

failed_hosts=""

for i in $proxy_targets
do

if http --check-status --ignore-stdin --timeout=2.5 --proxy=http:$i HEAD www.msftncsi.com/ncsi.txt &> /dev/null; then
    echo 'OK!'
else
    case $? in
        2) echo 'Request timed out!'| mail -s "The following WSA has failed to pass traffic with the following error" moe.abdel@childrens.ha
rvard.edu  ;;
        3) echo 'Unexpected HTTP 3xx Redirection!'| mail -s "The following WSA has failed to pass traffic with the following error" katkota@newwork.com  ;;
        4) echo 'HTTP 4xx Client Error!'| mail -s "The following WSA has failed to pass traffic with the following error" katkota@newwork.com  ;;
        5) echo 'HTTP 5xx Server Error!'| mail -s "The following WSA has failed to pass traffic with the following error" katkota@newwork.com  ;;
        6) echo 'Exceeded --max-redirects=<n> redirects!'| mail -s "The following WSA has failed to pass traffic with the following error" katkota@newwork.com  ;;
        *) echo 'Other Error!'| mail -s "The following WSA has failed to pass traffic with the following error" katkota@newwork.com ;;
    esac
fi
done;


Last edited by Katkota; 07-11-2018 at 11:32 PM..
 

7 More Discussions You Might Find Interesting

1. IP Networking

Software/tool to route an IP packet to proxy server and capture the Proxy reply as an

Hi, I am involved in a project on Debian. One of my requirement is to route an IP packet in my application to a proxy server and receive the reply from the proxy server as an IP packet. My application handles data at the IP frame level. My application creates an IP packet(with all the necessary... (0 Replies)
Discussion started by: Rajesh_BK
0 Replies

2. Shell Programming and Scripting

Traffic Monitoring Script

Hello All, I have written a script to check for http error code 500 in the logs. here is the code #!/bin/bash ######################################################################################################### # Shellscript : trafficchk.sh -Traffic Monitoring # Version ... (3 Replies)
Discussion started by: Siddheshk
3 Replies

3. AIX

Script for real time network traffic per process

Hi All Gurus, I want to write a script (bash/ksh/csh) which will show real time network traffic ( TCP or UDP ) generated by per process/PID. For both Linux/AIX system, as nethogs ( Linux package ) shows ? Any suggestion is MOST welcome. Thanks in Advance, Amritendu Das (1 Reply)
Discussion started by: linux.amrit
1 Replies

4. Shell Programming and Scripting

Script for real time network traffic per process

Hi All Gurus, I want to write a script (bash/ksh/csh) which will show real time network traffic ( TCP or UDP ) generated by per process/PID. For both Linux/AIX system, as nethogs ( Linux package ) shows ? Any suggestion is MOST welcome. Thanks in Advance, Amritendu Das (3 Replies)
Discussion started by: linux.amrit
3 Replies

5. IP Networking

How to run an script and its commands via proxy?

Hi, i used this tutorial which tells me to use following example command to proxify traffic from my linux export {http,https,ftp}_proxy=122.228.156.126:80 when i do this command from command line it works and then i curl http://site/ipcheck.php i see its proxified, which is what i want to... (5 Replies)
Discussion started by: postcd
5 Replies

6. IP Networking

Connecting via proxy chain to Upstream proxy

I need to configure a proxy on my local machine to use an upstream proxy (installed on another machine). The upstream proxy requires Digest/NTLM authorization. I want the local proxy to deal with the upstream proxy's authorization details and provides authorization free access to users that connect... (0 Replies)
Discussion started by: Russel
0 Replies

7. UNIX for Advanced & Expert Users

Proxy traffic consumption

Hello, I am under Ubuntu 16.04 at location1 and location2 and my question is about haproxy. I'd like to know when a port in location1 is redirected to another computer in location2, does incoming request to redirected port consume traffic both from 1 and 2 or just 2? What I'd like to accomplish... (6 Replies)
Discussion started by: baris35
6 Replies
SCRIPT(1)						    BSD General Commands Manual 						 SCRIPT(1)

NAME
script -- make typescript of terminal session SYNOPSIS
script [-adfpqr] [-c command] [file] DESCRIPTION
script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1). If the argument file is given, script saves all dialogue in file. If no file name is given, the typescript is saved in the file typescript. Option: -a Append the output to file or typescript, retaining the prior contents. -c command Run the named command instead of the shell. Useful for capturing the output of a program that behaves differently when associated with a tty. -d When playing back a session with the -p flag, don't sleep between records when playing back a timestamped session. -f Flush output after each write. This is useful for watching the script output in real time. -p Play back a session recorded with the -r flag in real time. -q Be quiet, and don't output started and ended lines. -r Record a session with input, output, and timestamping. The script ends when the forked shell exits (a control-D to exit the Bourne shell (sh(1)), and exit, logout or control-d (if ignoreeof is not set) for the C-shell, csh(1)). Certain interactive commands, such as vi(1), create garbage in the typescript file. script works best with commands that do not manipulate the screen, the results are meant to emulate a hardcopy terminal. ENVIRONMENT
The following environment variable is used by script: SHELL If the variable SHELL exists, the shell forked by script will be that shell. If SHELL is not set, the Bourne shell is assumed. (Most shells set this variable automatically). SEE ALSO
csh(1) (for the history mechanism). HISTORY
The script command appeared in 3.0BSD. BUGS
script places everything in the log file, including linefeeds and backspaces. This is not what the naive user expects. BSD
October 17, 2009 BSD
All times are GMT -4. The time now is 02:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy