Execute via crontab taking username/password from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute via crontab taking username/password from file
# 1  
Old 07-24-2009
CPU & Memory Execute via crontab taking username/password from file

Dear All
Here is the details what i want to achieve from shell scripts
I have a sever where 5 databases are created. which i having diffrent SID's.
Now i want to execute some SQL queries on each one of the databases. (SQL Query is same).That i want to acheive via crontab
Now each one of the database have diffrent login.for that i have created one DBCONFG.cfg file.
Now i want to achive something like, when this script will excute trough crontab, it should take the Usernaem ,password from DBCONFIG.cfg file based on SID
and connect to the database and should execute the SQL Query.
COntent of DBCONFIG.cfg file
LCSCT1|sedba|se_dba123
ENCUPID|encdba|enc_dba123
CIPA|cipadba|cipa_dba123
BELLSOUTH|belldba|bell_dba123
.
.
.
Like this where 1st field is "SID",2nd field is "username" and third filed is "password"
Now it should take the username/password based on SID
And i can take the SID form oratab file like this
ORATAB=/var/opt/oracle/oratab
SID=`egrep -i ":Y|:N" $ORATAB | cut -d":" -f1 | grep -v "\#" | grep -v "\*"`
echo $SID
Please help me how can achieve this.
# 2  
Old 07-24-2009
you can try something like this:

Code:
GetDetails ()
{
eval `awk -v sid="$SID" -F"|" '{ if ( $1 == sid ) { printf ("USER=%s\nPASS=%s\n", $2,$3) }}' cfg`
echo $SID;echo $USER;echo $PASS; echo ""
}
 
for SID in LCSCT1 ENCUPID CIPA BELLSOUTH
do
        GetDetails
        ## do what ever you want to do for each SID
done



output:

Code:
LCSCT1
sedba
se_dba123
 
ENCUPID
encdba
enc_dba123
 
CIPA
cipadba
cipa_dba123
 
BELLSOUTH
belldba
bell_dba123


Last edited by clx; 07-24-2009 at 01:09 PM..
# 3  
Old 07-24-2009
Hi jhon

DBLIST=`egrep -i ":Y|:N" /etc/oratab | cut -d":" -f1 | grep -v "\#" | grep -v "\*"`
for DBNAME in $DBLIST
do
username=`grep $DBNAME DBCONFIG.cfg | cut -d "|" -f2`
password=`grep $DBNAME DBCONFIG.cfg | cut -d "|" -f3`
sqlplus -s ${username}/${password} <<EOF
select name from v\$database;
select sysdate from dual;
EOF
done

scripter

Last edited by Franklin52; 07-24-2009 at 05:30 PM.. Reason: urls removed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with calling to file for a username and password combo

Hokay...first post, and I have been doing Linux scripting for a total of 2 days now. I think I am doing pretty well, but awk and arrays(what I think I need here) is a bit above me so far. I have written a script that will take and either create or modify 5 users, and passwords. It checks... (6 Replies)
Discussion started by: cashman04
6 Replies

2. Shell Programming and Scripting

Script taking more time in CRONTAB

Hello All, I have created a shell script, When i run it manually as ./<script_name> it takes 5 hours to run, but when i am scheduling it in crontab, it is taking 20 hours to run. Please help me and advice, what can be done to reduce the time in crontab. Thank you (6 Replies)
Discussion started by: anand2308
6 Replies

3. Shell Programming and Scripting

Username and password

Hi I am new to using unix and am struggling with a script i am writing. What i am trying to do is get a user to enter a username, check the original file i created with username and pin to see if their is a corresponding entry. Next ask the user to enter the pin and see if this matches... (5 Replies)
Discussion started by: somersetdan
5 Replies

4. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

5. Shell Programming and Scripting

Logging in unix account taking password from a parameter file

Hi All, I am writing a script where it updates a file in an unix account. To update that file i need to be logged in as that account user. say account name is ab01 and its password is passab01. What i want to do is, my script should read login id and password from a parameter file and... (4 Replies)
Discussion started by: pkbond
4 Replies

6. UNIX for Advanced & Expert Users

command taking lot of time to execute

Hi, I am running the following command, and it tries to delete some dn from ldap, however, it takes lot of time before it finally request LDAP server to delete it. I am trying to find why it is taking lot of time. Could you anyone help me in this regard. I have copies the pstack output, and... (3 Replies)
Discussion started by: john_prince
3 Replies

7. Shell Programming and Scripting

Read Oracle Username password SID from single file and pass it to shell

Dear All I am trying to write one shell which will be running through Cron which contain one SQL query. But I want to draw/fetch the Username password and Instance name (required to loging to the database) from one single file to run that SQL query . Also this file contain details of multiple... (2 Replies)
Discussion started by: jhon
2 Replies

8. AIX

How transfer sql file from one serverto another without username and password

hi there, Please help me How transfer sql file from one server to another without username and password .i know just IP address. Thanks Arpit (1 Reply)
Discussion started by: Arpitmitm
1 Replies

9. Shell Programming and Scripting

Shell script is taking more than 3 hrs to execute

Hi I am doing a process of converting all the values of key column into a row, for eg Key col1 col2 1 1 1 1 2 1 1 1 3 1 3 1 2 ... (2 Replies)
Discussion started by: nvuradi
2 Replies

10. Shell Programming and Scripting

Crontab error Cannot execute binary file.

Anyone can help me ? I try to using crontab with a simple shell script as echo it run okay but now i have more command in script. when I set entry to crontab and whe it run i get mail with error cannot execute binary file. it urgent so please help me the soutions. Thank so much for your help.... (5 Replies)
Discussion started by: raccsdl
5 Replies
Login or Register to Ask a Question