Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Bash STDOUT

Name: Anonymous 2012-09-21 8:29

I'm writing a script, and it's just about finished. Thing is, it calls a lot of sub-processes that spit terminal output to the screen. Now, I've figured out that you stop this with


exec 1>/dev/null 2>/dev/null


but I want to periodically re-enable STDOUT so I can echo updates about what the program is doing.

Any of you /prog/ geezers know what I should do?

Any and all answers appreciated. [spoiler]Yes, even you who is going to post REDIRECT MY ANUS.

Name: !L33tUKZj5I 2012-09-21 12:23

>>4
Please use [m] tags when pasting shell code. Syntax highlighting is too weird.
For you, I will.

Here's the code in case anyone cares. It's not finished yet (obviously) as it's only testing on port 8080. Next time I have a session on it, I'm going to add commandline flags for which ports/how many IP's to scan.

####################################################
# Proxyharvest V 0.9.                              #
#                                                  #
# Usage: ./proxyharvest                            #
#                                                  #
# Disclaimer: Don't use this program to be a dick. #
#                                                  #
# Written by withnail                              #
#                                                  #
####################################################

clear
echo "Starting the random proxy scan. This may take some time, please be patient."
exec 1>/dev/null 2>/dev/null
nmap -iR 10000 -p 8080 -oG /usr/share/proxyharvest/proxy_scan.txt
exec 1>/dev/tty
echo "Proxy scanning complete. Now checking whether found proxies are open."
echo " ";echo "Let's first fetch a file to use for proxy validity checking."
exec 1>/dev/null 2>/dev/null
wget microsoft.com/favicon.ico -O /usr/share/proxyharvest/checker.ico
exec 1>/dev/tty
if [ -f /usr/share/proxyharvest/checker.ico ] ; then echo " ";echo "Known good file fetched."; else echo "Unable to download the validity checker file! Please check your network connection."; fi
echo " ";echo "Ok, now checking found open ports. Bad proxies will be saved in another log in case you want to look at them.";echo " "
exec 1>/dev/null 2>/dev/null
    grep 8080/open /usr/share/proxyharvest/proxy_scan.txt|while read line;do
    echo $line|awk {'system ("wget -e http_proxy="$2":8080 microsoft.com/favicon.ico -O /usr/share/proxyharvest/temp.ico")'}
    diff /usr/share/proxyharvest/temp.ico /usr/share/proxyharvest/checker.ico
    if  [ $? -eq 0 ]
    then echo $line>>/usr/share/proxyharvest/known_good.txt;exec 1>/dev/tty;echo "Found one! Check logfiles";exec 1>/dev/null 2>/dev/null

    else exec 1>/dev/tty;echo "Proxy was false.";exec 1>/dev/null 2>/dev/null;echo $line>>/usr/share/proxyharvest/other_devices.txt
    rm /usr/share/proxyharvest/temp.ico
fi

done
exec 1>/dev/tty
echo "Program finished. Here are the known good proxies (if any):"
cat /usr/share/proxyharvest/known_good.txt



I've left that in a cron job now I know it works. Maybe sometime before Christmas it will find me a a proxy instead of a device config page that's been left open to the net.

Disclaimer: If you want to run this yourself, you need to create /usr/bin/proxyharvest yourself, otherwise it won't work. I'm going to write a makefile for it which checks all relevant needed programs are installed and creates the directory it needs.

In before massive flaming and telling me how shit I am.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List