I have a big problem. My script works well on my Debian Squeeze local VM and Mac OX 10.8 but not on my Debian server ... I checked all the versions of kernel, bash, ... It's the same on all !
My script :
#!/bin/bash
# Version 1.0
ipaddr=$1
datel=$(date +"%d/%m/%Y %k:%M")
function valid_ip()
{
local ip=$ipaddr
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]{1,2}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$?
fi
return $stat
}
valid_ip
if [ $? -eq "0" ]; then
nmap -sS -A $ipaddr --max-retries 3 -oX landiscover.xml --webxml 2>> nmap_error.log
echo "$datel Please wait during discover your network, this operation may take a while" >> landiscover.log
else
echo "$datel Please enter a valid network address : XXX.XXX.XXX./XX" >> landiscover.log
fi
if [ $? -eq "0" ]; then
echo "$datel Landiscover ran successfully !" >> landiscover.log
fi
When I run this script with debug option I have this output :
loterm_g@vm11:/opt$ sh -x landiscover.sh 192.168.1.0/24
+
: not found.sh: 1:
+ ipaddr=192.168.1.0/24
+ date +%d/%m/%Y %k:%M
+ datel=30/07/2013 1:54
+
: not found.sh: 1:
landiscover.sh: 8: Syntax error: "(" unexpected
Any idea ?
: not founderrors, and probably also the syntax error.ip=($ip)? Shouldn't that beip=$(ip)?$(ip)would try to run theipcommand and assign its output.ipis a command on my system. Could that be the problem?