我想要做的是拥有一个控制非常基本的备份脚本的配置文件。BASH在远程配置文件中具有相同名称的多个变量
#Credentials
username="backup.user"
password="****"
from="/mnt"
to="/home/backup"
#Mountpoints
n=1
source="//10.X.X.X/Public"
destination="/mnt/Public"
n=2
source="//10.X.X.X/it"
destination="/mnt/it"
脚本本身里面它看起来像这样:
#!/bin/bash
#getting variables from the external config file
export $(cat config.ini | grep -v ^# | xargs)
#the command I am trying to achieve
mountpoint[$n]="mount -t cifs -o username=$username,password=$password,ro $source $destination"
#mounts the array of mountpoints defined
for mountpoint in "${mountpoint[@]}";
do
${mountpoint}
done
function currentDate() {
date +%Y%m%d
}
if [ ! -d "$to/$(currentDate)" ] ; then
mkdir "$to/$(currentDate)";
cp --verbose -R "$from/." "$to/$(currentDate)" >> $to/$(currentDate)/fileLog.txt
diff -qr $from $to/$(currentDate) >> $to/$(currentDate)/differencesLog.txt
else
exit
fi
umount -a -t cifs -l /mnt/*
done
我试图做到这一点: 有一组变量配置为每个挂载点。
for循环for循环会回显最后的源和目标是正常的,因为它不知道什么时候为“n = 1”完成某一组变量。
你们会怎么做?
非常感谢!
请使用'源config.ini',而不是'$出口(猫的config.ini | grep的-v ^#| xargs的)' – hek2mgl
谢谢你的提示。 :) –
:)怎么样使用'json'的配置文件?这不会简化很多东西吗? – hek2mgl