在工作中,我们有7或8个派往全国各地的硬盘驱动器,每个硬盘驱动器都有唯一的不连续的标签。BASH,多个阵列和一个循环
理想情况下,驱动器插在我们的桌面上,然后从服务器获取与驱动器名称对应的文件夹。
有时,只有一个硬盘驱动器有时会插入倍数,未来可能会增加更多。
每个都安装到/卷/及其标识符;例如/ Volumes/f00,其中f00是标识符。
我想要发生的情况是扫描卷,看是否有任何驱动器插入,然后检查服务器以查看文件夹是否存在,是否存在复制文件夹和递归文件夹。
这里是我迄今为止,它会检查驱动器卷上存在:
#!/bin/sh
#Declare drives in the array
ARRAY=(foo bar long)
#Get the drives from the array
DRIVES=${#ARRAY[@]}
#Define base dir to check
BaseDir="/Volumes"
#Define shared server fold on local mount points
#I plan to use AFP eventually, but for the sake of ease
#using a local mount.
ServerMount="BigBlue"
#Define folder name for where files are to come from
Dispatch="File-Dispatch"
dir="$BaseDir/${ARRAY[${i}]}"
#Loop through each item in the array and check if exists on /Volumes
for ((i=0;i<$DRIVES;i++));
do
dir="$BaseDir/${ARRAY[${i}]}"
if [ -d "$dir" ]; then
echo "$dir exists, you win."
else
echo "$dir is not attached."
fi
done
我想不出该怎么办,是怎么检查在循环硬盘安装点时服务器的卷。
所以我可以做类似:
#!/bin/sh
#Declare drives, and folder location in arrays
ARRAY=(foo bar long)
#Get the drives from the array
DRIVES=${#ARRAY[@]}
#Define base dir to check
BaseDir="/Volumes"
#Define shared server fold on local mount points
ServerMount="BigBlue
#Define folder name for where files are to come from
Dispatch="File-Dispatch"
dir="$BaseDir/${ARRAY[${i}]}"
#List the contents from server directory into array
ARRAY1=($(ls ""$BaseDir"/"$ServerMount"/"$Dispatch""))
SERVERFOLDER=${#ARRAY1[@]}
echo ${list[@]}
for ((i=0;i<$DRIVES;i++)); ((i=0;i<$SERVERFOLDER;i++));
do
dir="$BaseDir/${ARRAY[${i}]}"
ser="${ARRAY1[${i}]}"
if [ "$dir" =~ "$sir" ]; then
cp "$sir" "$dir"
else
echo "$dir is not attached."
fi
done
我知道,这是非常错误的...非常好,但我希望它给你什么,我想实现的想法。
任何想法或建议吗?
对不起,这些错误中的一半来自于我懒惰复制到这里和编辑时,但谢谢我也会试试这个。我知道((i = 0; i <$ DRIVES; i ++)); ((i = 0; i <$ SERVERFOLDER; i ++));是不正确的,但这是我想要的。 你在上个月帮我解决了一些问题,我非常感谢。 – S1syphus 2010-04-30 15:21:45