This shell script is designed for a specific task required for our server. So sharing the script with Tecadmin readers. It might be helpful for you.

Advertisement

Requirement

Our requirement is to copy all files created in directory to other directory with same directory structure. Script will run on a regular interval, search for all files created in source directory and copy them to destination directory. The script must maintain the same directory structure on destination directory. After that change the permission on destination directory. After successful copy of file, script must remove the file from source directory.

Shell Script

Create a shell script on your system and add below content. Update source and destination directories to proper location.

Set CHANGE_OWNERSHIP to 0, if you don’t want to change ownership on destination files.

Save your file and close it.

Then set the execute permission to the script file.

chmod +x script.sh
Share.

1 Comment

  1. Nice to see shell script.
    Using cp -R SOURCE_DIR DEST_DIR
    will do same operation to copy files from source to destination retains directory structure?

Leave A Reply

Exit mobile version