Linux мв команда и затем выключение - PullRequest
0 голосов
/ 24 апреля 2020

У меня есть небольшой 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

Я заметил, что после перезагрузки только иногда файлы не перемещаются в целевую, и мне было интересно если эта команда выключения может быть проблемой. Нужно ли вызывать syn c перед выключением?

1 Ответ

1 голос
/ 24 апреля 2020

Исправлен скрипт с комментариями:

#!/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
...