Shell script duplicate directory, lock it and move both to a new directory - almost there?

I am a reporter who works with data sets. Every time I get a new data set, I do two things at once: duplicate the file and lock the originals.

I want to automate this process. By changing the shell of the script, I use to create subfolders for creating project reports and imposing it along with a set of commands, I was able to achieve the main functionality, but it is dirty. I would be grateful for your help in streamlining.

Here's what I'm doing right now (bear with me, and I promise to be as clear as possible):

I load the data into a desktop folder called "DataInbox", where I also have the following shell script saved as newdata.sh:

#!/bin/bash if [[ -z "${1}" ]]; then die "FolderName Required" fi /bin/mkdir -p ~/Desktop/DataFarm/$1/{ProtectedOrig,Data} echo -n "---Data Folder Setup ---Data Introduction ---Data Audit/Manipulation ---Data Queries" > ~/Desktop/DataFarm/$1/Data/DataJournal.txt 

By executing bash newdata.sh DirectoryName , I create a directory with subfolders "Data" and "Protected Orig" and a text file "DataJournal.txt" with four headers.

Inside the DataInbox directory, I run this mess, only strung together with && :

 $ ditto NewData/ NewDataCopy $ bash newdata.sh DirectoryName $ mv NewData/ /Users/JSG/Desktop/DataFarm/DirectoryName/ProtectedOrig/NewData $ mv NewDataCopy/ /Users/JSG/Desktop/DataFarm/DirectoryName/Data/NewDataCopy $ chflags -R uchg /Users/JSG/Desktop/DataFarm/DirectoryName/ProtectedOrig/ 

As I said, I would like to rationalize this. In fact, what I really would like to do is turn all this into a shell script, and I'm struggling to get it to work. Thank you in advance from a beginner to beginner.

+1
source share
1 answer

Not sure if I do not understand your question, but you want to combine all this into one script as follows:

 #!/bin/bash if [[ -z "${1}" ]]; then die "FolderName Required" fi newDirName="DirectoryName" newBaseDir="~/Desktop/DataFarm/$1/" /bin/mkdir -p $newBaseDir/{ProtectedOrig,Data} echo -n "---Data Folder Setup ---Data Introduction ---Data Audit/Manipulation ---Data Queries" > $newBaseDir/Data/DataJournal.txt ditto NewData/ NewDataCopy newdata.sh $newDirName mv NewData/ $newBaseDir/ProtectedOrig/NewData mv NewDataCopy/ $newBaseDir/Data/NewDataCopy chflags -R uchg $newBaseDir/ProtectedOrig/ 
+2
source

All Articles