Скажите, а как проверить переменную которую сует пользователь в sh-скрипт.
Например, надо проверить является ли введенная переменная IP-адресом.
#!/bin/sh
# RDP share/unshare script by /random/+
# 07.09.2008 11:41
# user defined variables
# officeIP - IP адрес роутер через который идет "проброс" порта; эта переменная, для удобства, определяется в самом sh-скрипте
# sharingIP - IP адрес компьютера который надо "выбросить" за роутер, наружу
# remoteIP - IP адрес для которого разрешены соединения на заданный порт, можно указывать целые подсети, например 91.198.111.0/24 или 91.198.0.0/16
# sharingPORT - порт на который будет производиться подключение клиента к серверу, это не порт который надо "пробросить" (!)
officeIP=127.0.0.1
sharingIP=$2
remoteIP=$3
sharingPORT=$4
# end user defined variables
if [ "$2" -a "$3" -a "$4" ]; then
case "$1" in
'add')
echo Adding share to $sharingIP:3389 on port $sharingPORT on $officeIP. Only $remoteIP allow to connect!
iptables -t nat -A PREROUTING -p tcp -m tcp -s $remoteIP -d $officeIP --dport $sharingPORT -j DNAT --to-destination $sharingIP:3389
iptables -t filter -A FORWARD -p tcp -m tcp -s $remoteIP -d $sharingIP -i eth0 --dport 3389 -j ACCEPT
;;
'del')
echo Deleting share to $sharingIP:3389 on port $sharingPORT on $officeIP. Only $remoteIP was allow to connect!
iptables -t nat -D PREROUTING -p tcp -m tcp -s $remoteIP -d $officeIP --dport $sharingPORT -j DNAT --to-destination $sharingIP:3389
iptables -t filter -D FORWARD -p tcp -m tcp -s $remoteIP -d $sharingIP -i eth0 --dport 3389 -j ACCEPT
;;
esac
elif [ "$1" == "status" ]; then
echo "------RDP status------
"
echo "---filter table---"
iptables -t filter -L | grep 3389
echo "---nat table---"
iptables -t nat -L | grep 3389
echo "
-----end RDP status------"
elif [ "$1" == "help" ]; then
echo "Usage: $0 { add | del | status | help }
example: sharerdp add 10.1.2.4 127.0.0.1 4477 - add a rdp share for computer 10.1.2.4:3389 on port 4477 and only 127.0.0.1 can connect
example: sharerdp add 10.1.2.4 91.198.111.0/24 4477 - add a rdp share for computer 10.1.2.4:3389 on port 4477 and only 91.198.111.0/24 network can
example: sharerdp del 10.1.2.4 127.0.0.1 4477 - removes a rdp share for computer 10.1.2.4:3389 on port 4477
example: sharerdp status - shows active shares from iptables using 'iptables -t [table] - L'
"
else
echo "You must provide sharing IP, remote IP which would allow to connect and sharing port.
Use 'sharerdp help' to show help message";
fi
exit 0
Тут хочу проверить IP и порты.