使用Linux mv命令,然后关机

问题描述 投票:0回答:1

我有一个小的bash脚本(简化版),运行在Ubuntu 16.04上。

tar zxvf fileNameHere.tgz  <-- Untar tgz file in $SRC_DIR
files=$(ls $SRC_DIR)
echo "Extracting $files"  >> $APP_LOG_DIR/update.log
mv $SRC_DIR/* $OUTPUT_DIR
shutdown -r now

我注意到,在重启后,只有有时文件没有被移动到目标位置,我想知道是否是关机命令的问题。是否有必要在关机前调用 "sync"?

linux bash rsync shutdown
1个回答
1
投票

修正了带有注释的脚本。

#!/usr/bin/env bash

# Test if SRC_DIR and OUTPUT_DIR are actual directories
if [ -d "$SRC_DIR" ] && [ -d "$OUTPUT_DIR" ]; then

  # Populates the arguments array with the content
  # of SRC_DIR rather than parsing the output of ls
  set -- "$SRC_DIR/"*

  # Prints joined file entries of the arguments array
  # while stripping their leading directory path
  printf 'Extracting %s\n' "${*#*/}" >> "$APP_LOG_DIR/update.log"

  # Moves all the arguments array's entries (the actual 
  # content of the SRC_DIR) into OUTPUT_DIR
  mv -- "$@" "$OUTPUT_DIR/"
  shutdown -r now
fi
© www.soinside.com 2019 - 2024. All rights reserved.