Bash: pass host variable to traceroute

1.1k Views Asked by At

I wrote a script to run a traceroute on a series of ip ranges. When I use the default options (that is, when I run traceroute without any additional options), my script runs fine. In other words:

traceroute "$hostip" 

Produces the desired result.

However when I utilize the options I need, traceroute fails to run, stating no host has been provided:

traceroute -p 25 -M tcp "$hostip"
Specify "host" missing argument.

I'm really at a loss. I've tried a couple different combinations, none of which work. I'm failing to comprehend why this command works in the first fashion, but not with options enabled!

I have traceroute-2.0.19-x86_64-1 on slackware64-current. Any help is greatly appreciated!

Here is a shortened version of what i'm working with:

#!/bin/bash
#
# tracert_efax-smtp.sh
#
# Diego Pineda 8132015

# output
foi='1'
fp='/home/slugman/Data'
fileo="$fp/tracert_efax-smtp.$foi"


# while loop 181 - 183
ip1a="216.24.224."
ip1b="181"


# Create fileo
if [ -e $fileo ]; then
        (( foi++ ))
        fileo="$fp/tracert_efax-smtp.$foi"
        touch $fileo
else
        touch $fileo
fi


# test ip1 series
echo "Testing $ip1a$ip1b - 183" >> $fileo
while [ $ip1b -le 183 ]; do
        traceroute -p 25 -M tcp "$ip1a$ip1b" >> "$fileo"
        (( ip1b++ ))
done
0

There are 0 best solutions below