-1

I am trying to make a checkpoint management script, which will delete all checkpoints that are over 3 days old for a variety of databases. I want to keep the code in one script and then keep a list of all the paths to each database I want to manage in another.

How do I reference the file with the list of databases, so I can use them in a for loop? In the loop, how do I change directories to each directory listed in the text file?

Ex. File with list of databases (db.list):

/directory/directory/databse1

/directory/directory/databse4

/directory/directory/databse10

Ex. Code:

for database in db.list

do
   cd $database
   code

done 
conor.ob
  • 87
  • 1
  • 2
  • 9

1 Answers1

3

A file listing database paths wouldn't be called a script. It just a text file.

To iterate over lines of a text file, you can read the file:

while read -r database ; do
    echo "$database"
done < db.list
choroba
  • 231,213
  • 25
  • 204
  • 289