0

I'm trying convert some files to read only in backup environment. Data Domain has retention-lock feature that can lock files with external trigger which touch -a -t "dateuntillocked" /backup/foo. In this situation there is also metadata files in folder that should not be locked otherwise next backup job cannot update metadata file and fails. I extracted metadata file names but file count can be changed. For exp. foo1.meta foo2.meta . . fooN.meta

Is it possible to create a variable for each entry and add to command dynamically? Like: var1=/backup/foo234.meta var2=/backup/foo322.meta . . varN=/backup/fooNNN.meta

<find command> | grep -v $var1 $var2....varN | while read line; do touch -a -t "$dateuntillocked" "$line"; done

another elaboration of the case is for example you executed a ls in a folder but amount of file can differs in time. script will create a variable for every file and use in a touch command with while loop. if 3 files in folder, script will create 3 variable and use 3 variable with touch in while loop. if "ls" result find 4 files, script dynamically create 4 variable fof files and use all in while loop etc. I am not a programmer so my logic can differ. May be another way to do this with easier way.

Rusty
  • 1
  • 2
  • It's not clear what your sample code has to do with your question. – Charles Duffy Jun 21 '22 at 15:38
  • That said, it looks like you want to use an array, to dynamically expand a command line, as described in [BashFAQ #50](https://mywiki.wooledge.org/BashFAQ/050). – Charles Duffy Jun 21 '22 at 15:39
  • Also, to let changes it makes to your array persist, you'll need to change the way you get data into your `while read` loop for the reasons described in [BashFAQ #24](https://mywiki.wooledge.org/BashFAQ/024). – Charles Duffy Jun 21 '22 at 15:39
  • ...for more on bash arrays, see [BashFAQ #5](https://mywiki.wooledge.org/BashFAQ/005). – Charles Duffy Jun 21 '22 at 15:41
  • ...but to provide an actual _answer_, as opposed to a bunch of relevant-looking links, I'll need a [mre] -- code I can run myself without changes to see the same problem, with stated desired output that if present would imply that it's fixed / operating as-intended. – Charles Duffy Jun 21 '22 at 15:41
  • refer to this , might be helpful. https://stackoverflow.com/questions/16553089/dynamic-variable-names-in-bash – John vinith Jun 21 '22 at 17:37

1 Answers1

0

Just guessing what your intentions might be.

You can combine find | grep | command into a single command:

find /backup -name 'foo*.meta' -exec touch -a -t "$dateuntillocked" {} +
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134