请用Shell脚本帮助修复它
我运行的示例 sh麦科德马努gg44 我需要一份名为Manu的文件 内容包括: gg44 192.168.1.2.(第二行)(这个数字我在下面解释) (目录DIR=/h/Manu/HOME/hosts中已经有文件Alex 猫亚历克斯 ff55 198.162.1.1.(第二行)) 因此,mycode使用第一行gg44创建名为Manu的文件,并在第二行生成IP。 但对于生成IP,他已经将其与Alex文件IP进行了比较。所以Manu的第二行必须是198.162.1.2。如果目录中有多个文件,则必须检查所有文件的所有第二行,然后根据它们生成请用Shell脚本帮助修复它,shell,Shell,我运行的示例 sh麦科德马努gg44 我需要一份名为Manu的文件 内容包括: gg44 192.168.1.2.(第二行)(这个数字我在下面解释) (目录DIR=/h/Manu/HOME/hosts中已经有文件Alex 猫亚历克斯 ff55 198.162.1.1.(第二行)) 因此,mycode使用第一行gg44创建名为Manu的文件,并在第二行生成IP。 但对于生成IP,他已经将其与Alex文件IP进行了比较。所以Manu的第二行必须是198.162.1.2。如果目录中有多个文件,则必须检
[CODE]
DIR=/h/Manu/HOME/hosts #this is a directory where i have my files (structure of the files above)
for j in $1 $2 #$1 is Manu; $2 is gg44
do
if [ -d $DIR ] #checking if directory exists (it exists already)
then #if it exists
for i in $* # for every file in this directory do operation
do
sort /h/ManuHOME/hosts/* | tail -2 | head -1 # get second line of every file
IFS="." read A B C D # divide number in second line into 4 parts (our number 192.168.1.1. for example)
if [ "$D" != 255 ] #compare D (which is 1 in our example: if its less than 255)
then
D=` expr $D + 1 ` #then increment it by 1
else
C=` expr $C + 1 ` #otherwise increment C and make D=0
D=0
fi
echo "$2 "\n" $A.$B.$C.$D." >/h/Manu/HOME/hosts/$1
done done #get $2 (which is gg44 in example as a first line and get ABCD as a second line)[/CODE]
结果,它创建了名为Manu的文件,第一行,但第二行是完全错误的。它给了我…1。
还有错误消息
排序:打开失败:/h/u15/c2/00/c2rsaldi/HOME/hosts/yu:没有这样的文件或目录
yu n…1.#/bin/bash
#!/bin/bash
dir=/h/Manu/HOME/hosts
filename=$dir/$1
firstline=$2
# find the max IP address from all current files:
maxIP=$(awk 'FNR==2' $dir/* | cut -d. -f4 | sort -nr | head -1)
ip=198.162.1.$(( maxIP + 1 ))
cat > $filename <<END
$firstline
$ip
END
dir=/h/Manu/HOME/hosts
filename=$dir/$1
一线=2美元
#从所有当前文件中查找最大IP地址:
maxIP=$(awk'FNR==2'$dir/*| cut-d-f4 | sort-nr | head-1)
ip=198.162.1.$(最大ip+1))
cat>$filename“yu n…1”?我跟不上这些新的首字母缩略词。首先,你错过了一个fi
语句。剩下的就乱七八糟了。。。正确缩进你的代码,这会有帮助。用:sh-x-vmycodemanugg44egads测试你的脚本!你必须开始缩进你的代码。