I am writing some code in Python that is almost working, but there is one thing I am unable to figure out.
I need to loop through 2 lists. I want to loop through until the first list is complete; whereas the second list should repeat itself until the first list is complete.
I want to input a list of databases and a list of streams. Then I want the code to output the 9 lines by replacing where it has "+ stream +" and "+ item +". The item part works fine, but I don't know how to output the list of streams while iterating through the list of databases. I want the streams to cycle through and then repeat. So it will start at 1a and then reach 3c, and then start over again at 1a. I want this to happen until it reaches the last database in the list.
databases=input("Enter databases: ") streams="1a 2a 3a 1b 2b 3b 1c 2c 3c" stream="1a" db_list = databases.split() streams_list= streams.split() for item in db_list: print("unlink $ORACLE_BASE/admin/" + item + "/backup") print("unlink $ORACLE_BASE/admin/" + item + "/dpdump") print("unlink $ORACLE_BASE/admin/" + item + "/exp") print("mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM" + stream + "/" + item + "/backup") print("mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM" + stream + "/" + item + "/dpdump") print("mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM" + stream + "/" + item + "/exp") print("ln -s $ORACLE_BASE/acfsmounts/global/STREAM" + stream + "/" + item + "/backup $ORACLE_BASE/admin/" + item + "/backup") print("ln -s $ORACLE_BASE/acfsmounts/global/STREAM" + stream + "/" + item + "/dpdump $ORACLE_BASE/admin/" + item + "/dpdump") print("ln -s $ORACLE_BASE/acfsmounts/global/STREAM" + stream + "/" + item + "/exp $ORACLE_BASE/admin/" + item + "/exp") Here is the output:
Enter databases: database1 database2 database3 unlink $ORACLE_BASE/admin/database1/backup unlink $ORACLE_BASE/admin/database1/dpdump unlink $ORACLE_BASE/admin/database1/exp mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM1a/database1/backup mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM1a/database1/dpdump mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM1a/database1/exp ln -s $ORACLE_BASE/acfsmounts/global/STREAM1a/database1/backup $ORACLE_BASE/admin/database1/backup ln -s $ORACLE_BASE/acfsmounts/global/STREAM1a/database1/dpdump $ORACLE_BASE/admin/database1/dpdump ln -s $ORACLE_BASE/acfsmounts/global/STREAM1a/database1/exp $ORACLE_BASE/admin/database1/exp unlink $ORACLE_BASE/admin/database2/backup unlink $ORACLE_BASE/admin/database2/dpdump unlink $ORACLE_BASE/admin/database2/exp mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM1a/database2/backup mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM1a/database2/dpdump mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM1a/database2/exp ln -s $ORACLE_BASE/acfsmounts/global/STREAM1a/database2/backup $ORACLE_BASE/admin/database2/backup ln -s $ORACLE_BASE/acfsmounts/global/STREAM1a/database2/dpdump $ORACLE_BASE/admin/database2/dpdump ln -s $ORACLE_BASE/acfsmounts/global/STREAM1a/database2/exp $ORACLE_BASE/admin/database2/exp unlink $ORACLE_BASE/admin/database3/backup unlink $ORACLE_BASE/admin/database3/dpdump unlink $ORACLE_BASE/admin/database3/exp mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM1a/database3/backup mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM1a/database3/dpdump mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM1a/database3/exp ln -s $ORACLE_BASE/acfsmounts/global/STREAM1a/database3/backup $ORACLE_BASE/admin/database3/backup ln -s $ORACLE_BASE/acfsmounts/global/STREAM1a/database3/dpdump $ORACLE_BASE/admin/database3/dpdump ln -s $ORACLE_BASE/acfsmounts/global/STREAM1a/database3/exp $ORACLE_BASE/admin/database3/exp My output has STREAM1a every time, but I want it to cycle through the pattern of 1a, 2a, 3a, 1b, 2b, 3b, 1c, 2c, and 3c. As mentioned, if I have more than 9 databases, then it would start over at 1a again. How can I achieve this?
The only part of my code that isn't working the way I want is where it says "+ stream +".
streams for each item indb_list? For example,database1 1a,database1 2a,database1 3a, etc.?