patternbashMinor
GRE Tunnel Script
Viewed 0 times
scriptgretunnel
Problem
I've made this script above for GRE Tunnels and I'd like to know how I can improve it.
Also, at the bottom, you'll see "Do you want to forward more ports." I want an easier method of asking this and inputting the info. The method I have right now is lone and not neat.
I want to be able to input ports separated by commas as a user, and I want the iptables commands (below) to be run for each of the ports they input, separated by commas.
```
#!/bin/bash -e
clear
echo "Kaveen's GRE Tunnel script"
echo ""
echo "This script requires an external package to be installed on your system called SSHPass, This allows this script to remote login to your customer's/secondary box"
echo ""
echo "If you are unsure of the packages that are going to be installed, just check the script itself using a text editor"
echo ""
apt-get update
sleep 1
apt-get install sshpass
sleep 1
echo "Repositories updated and SSHPass installed"
sleep 1
read -p "Your Filtered IP:" fillip
if ip route get $fillip &>/dev/null; then
echo "$fillip IP Validation Passed"
else
echo "$fillip IP Validation failed"
echo "Valid IP Ranges are from 0.0.0.0 - 255.255.255.255"
exit
fi
read -p "Customers main IP:" cusip
if ip route get $cusip &>/dev/null; then
echo "$cusip IP Validation Passed"
else
echo "$cusip IP Validation failed"
echo "Valid IP Ranges are from 0.0.0.0 - 255.255.255.255"
echo "Program exiting"
exit
fi
read -p "Your secondary IP:" secip
if ip route get $secip &>/dev/null; then
echo "$secip IP Validation Passed"
else
echo "$secip IP Validation Failed"
echo "Valid IP Ranges are from 0.0.0.0 - 255.255.255.255"
echo "Program exiting"
exit
fi
read -p "Port you wish to forward:" port
if [[ $port -gt 0 && $port -lt 65535 ]]; then
echo "Port $port is probably OK"
else
echo "$port Port validation failed"
echo "Valid port ranges are 0-65535"
echo "Program exiting"
exit
fi
echo ""
echo "IP Area completed"
echo "Moving on to remote host inf
Also, at the bottom, you'll see "Do you want to forward more ports." I want an easier method of asking this and inputting the info. The method I have right now is lone and not neat.
I want to be able to input ports separated by commas as a user, and I want the iptables commands (below) to be run for each of the ports they input, separated by commas.
```
#!/bin/bash -e
clear
echo "Kaveen's GRE Tunnel script"
echo ""
echo "This script requires an external package to be installed on your system called SSHPass, This allows this script to remote login to your customer's/secondary box"
echo ""
echo "If you are unsure of the packages that are going to be installed, just check the script itself using a text editor"
echo ""
apt-get update
sleep 1
apt-get install sshpass
sleep 1
echo "Repositories updated and SSHPass installed"
sleep 1
read -p "Your Filtered IP:" fillip
if ip route get $fillip &>/dev/null; then
echo "$fillip IP Validation Passed"
else
echo "$fillip IP Validation failed"
echo "Valid IP Ranges are from 0.0.0.0 - 255.255.255.255"
exit
fi
read -p "Customers main IP:" cusip
if ip route get $cusip &>/dev/null; then
echo "$cusip IP Validation Passed"
else
echo "$cusip IP Validation failed"
echo "Valid IP Ranges are from 0.0.0.0 - 255.255.255.255"
echo "Program exiting"
exit
fi
read -p "Your secondary IP:" secip
if ip route get $secip &>/dev/null; then
echo "$secip IP Validation Passed"
else
echo "$secip IP Validation Failed"
echo "Valid IP Ranges are from 0.0.0.0 - 255.255.255.255"
echo "Program exiting"
exit
fi
read -p "Port you wish to forward:" port
if [[ $port -gt 0 && $port -lt 65535 ]]; then
echo "Port $port is probably OK"
else
echo "$port Port validation failed"
echo "Valid port ranges are 0-65535"
echo "Program exiting"
exit
fi
echo ""
echo "IP Area completed"
echo "Moving on to remote host inf
Solution
Nitpicks
Why do you keep calling
You should also add some blanks lines into this code, as well as some comments. By adding blank lines and comments you can improve the clarity, and readability of your code.
I'm also noticing a few inconsistencies with your
And in other places, you call
I'd recommend that you choose a style rather than mixing two.
Why do you keep calling
sleep? As far as I can tell, it only pauses execution and isn't needed here. It's rather annoying to have to wait when the code executes.You should also add some blanks lines into this code, as well as some comments. By adding blank lines and comments you can improve the clarity, and readability of your code.
I'm also noticing a few inconsistencies with your
echo calls. For example, in many places, you use quotes, "", to echo a message, like this:echo "Program exiting"And in other places, you call
echo without quotes, like this:echo Confirmed, Continuing setupI'd recommend that you choose a style rather than mixing two.
Code Snippets
echo "Program exiting"echo Confirmed, Continuing setupContext
StackExchange Code Review Q#100748, answer score: 2
Revisions (0)
No revisions yet.