Jump to content
  • 0

Need help to write a logic to write shell script


Question

Hello,

I'm new to shell scripting and I know little basics. Could you please check my below requirement and then suggest me how can I write a logic.

I've to read files(krb5cc_a_db is the filename) from below folder in a sequence and should be written into environment variable , and then connects to database using sqlplus in a sequence for different databases.

/var/kerberos/a_system/cc/krb5cc_a_db

/var/kerberos/a_system/cc/krb5cc_a_db1

/var/kerberos/a_system/cc/krb5cc_a_db2

 

for this requirement I've written below proto type code so please check and correct me. Thanks in advance.

================================================

#basically below code does , first it reads 3 kerberos cache files from the directory and then connects to 1st database(testdb1) in a sequence for 3 users,and then again 3 users should connect to 2nd database(testdb2), same way it should work for all databases mentioned in the "db_service_list" variable.

db_service_list=("testdb1 testdb2 testdb3 testdb4")

for i in 'ls /var/kerberos/a_system/cc/krb5cc*'

do

    export KRB5CCNAME=$i

           for j in $db_service_list

           do

               sqlplus /@ $j <<EOF

               select systimestamp from dual;

                exit;

               EOF

         done

done

=================

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0
On 10/23/2020 at 10:01 AM, Prat said:

Hello,

I'm new to shell scripting and I know little basics. Could you please check my below requirement and then suggest me how can I write a logic.

I've to read files(krb5cc_a_db is the filename) from below folder in a sequence and should be written into environment variable , and then connects to database using sqlplus in a sequence for different databases.

/var/kerberos/a_system/cc/krb5cc_a_db

/var/kerberos/a_system/cc/krb5cc_a_db1

/var/kerberos/a_system/cc/krb5cc_a_db2

 

for this requirement I've written below proto type code so please check and correct me. Thanks in advance.

================================================

#basically below code does , first it reads 3 kerberos cache files from the directory and then connects to 1st database(testdb1) in a sequence for 3 users,and then again 3 users should connect to 2nd database(testdb2), same way it should work for all databases mentioned in the "db_service_list" variable.

db_service_list=("testdb1 testdb2 testdb3 testdb4")

for i in 'ls /var/kerberos/a_system/cc/krb5cc*'

do

    export KRB5CCNAME=$i

           for j in $db_service_list

           do

               sqlplus /@ $j <<EOF

               select systimestamp from dual;

                exit;

               EOF

         done

done

=================

Hi Prat,
Is the shell script working as expected? Are you facing any problems? 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...