获取fleetctl文件和本地文件之间的差异

时间:2015-12-14 15:12:47

标签: diff fleetctl

我在fleetctl中有一个文件,我们称之为file@123.service 我有一个本地文件,我们称之为文件@ .service

我想检查它们是否不同。 如果它们不同,我将启动一个销毁和启动命令,但我找不到在它们之间进行区分的方法..

我所做的是构建了一个脚本:

check_diff ()
{
    # Check if local file is diff from fleetctl file "file@123.service"
    # file@123.service is currently active in the fleetctl
    # Looking for something like
      diff (fleetctl list-units | grep $1 | head -n 1 | awk '{print $1}') $1.service
}

# Get local file names and push them to the function
for unit in $(ls -l | awk '{print $9}' | grep -e \.service); do
  check_diff ${unit%.*} # Will result unit as "file@"
done

1 个答案:

答案 0 :(得分:0)

<强> 解决方案:

找到解决方案

DIFF=$(fleetctl cat $fleetctlFile | diff -q -w ~/$localServiceUnit -)

然后检查$ DIFF var

if [ -z "$DIFF" ]
then
  echo "No DIFF"
else
  echo "DIFF was found"
fi