shell script to move files

need:

Move all files under /iotdata/data/edge/ota-file-store/ to the /iotdata/data/edge/download/ota directory, and delete the old directory

shell command

mkdir -p /iotdata/data/edge/download/ota/; cp -r /iotdata/data/edge/ota-file-store/. /iotdata/data/edge/download/ota/;rm -rf /iotdata/data/edge/ota-file-store

shell script

#!/bin/bash

dest_dir="/iotdata/data/edge/download/ota"
src_dir="/iotdata/data/edge/ota-file-store"
 
if [ ! -d ${dest_dir} ]; then
  mkdir -p ${dest_dir}
  echo "新增文件夹/iotdata/data/edge/download/ota成功"
fi 

if [ -d ${src_dir} ]&&[ -e ${src_dir} ]; then
  cp -R ${src_dir}/. ${dest_dir}/
  echo "复制原文件夹的固件到新文件夹成功"
fi
 
if [ -d ${src_dir} ]; then
  rm -R ${src_dir}
  echo "删除旧固件文件夹"
fi

ansible script

---

- hosts: all
  tasks:
    - name: create a new ota directory if it doesn't exist
      file:
        path: "{
    
    {target_root_dir}}/data/edge/download/ota"
        state: directory

    - name: Check old ota file path exists
      stat:
        path: "/iotdata/data/edge/ota-file-store"
      register: ota_file_store_stat

    - name: move old ota files to new path
      command: "cp -r /iotdata/data/edge/ota-file-store/. /iotdata//data/edge/download/ota/"
      when: ota_file_store_stat.stat.exists

    - name: Remove old ota file path
      file:
        path: "/iotdata/data/edge/ota-file-store"
        state: absent
      ignore_errors: yes
      when: ota_file_store_stat.stat.exists

Guess you like

Origin blog.csdn.net/qq_38923792/article/details/125558783