Hehe
I forgot some quotes in the test to see if there are any results...
if [ -z "$RESULT" ]; then
So you were right that it was interpreting the output instead of just treating it as text. I just wasn't noticing the error because it was scrolled off my screen
Here's the corrected script:
Code:
#!/bin/sh
#
# This is a script to retrieve default passwords for network devices
# Original script by: gubluntu
# Modifications by: jeo
# First we want to make sure the user has supplied an argument
# If not, we tell them what the script expects with a "usage"
# line and exit
if [ $# == 0 ]; then
echo "usage: $(basename $0) <mfg.> or <model#>"
echo "Lists possible default passwords for network devices"
exit 0
fi
# Here we'll set the URL. I assume at this point that if the
# URL changes, the entire script will have to change, but still...
URL="http://www.phenoelit.de/dpl/dpl.html"
# Now let's grab the list from our URL, convert it into a
# comma seperated list, grab only lines containing commas (to
# get rid of any irrelevant info), and store it in memory
# in the form of a variable. We'll call it "DATA".
DATA="$(curl -s $URL|sed s/"<\/TD>"/","/g | sed s/"<TD>"/""/g |grep ",")"
# From our comma seperated list, let's extract the
# column headers and store them in a variable
HEADER="$(echo "$DATA"| head -n1)"
# And now let's grab the lines that we're looking for
RESULT="$(echo "$DATA"| grep -i $1)"
# We can also say something useful if we don't find
# what we're looking for
if [ -z "$RESULT" ]; then
echo "Sorry, couldn't find anything for \"$1\""
exit
else
# Still part of our "if"
# And last but not least, we pipe our processed list
# (including headers) through "column" to get a pretty
# print-out. Problem here is if your terminal isn't wide
# enough, some word-wrapping happens... Perhaps we could
# pipe this to a text viewer that doesn't do wraping?
echo -e "$HEADER"\\n"$RESULT" | column -ntx -s","
fi
exit 0