Sponsored Content
Top Forums Shell Programming and Scripting How to validate Database password in ksh? Post 302593979 by knight_eon on Monday 30th of January 2012 05:03:11 AM
Old 01-30-2012
Quote:
Originally Posted by Chubler_XL
OK looks like sqlplus is returning 0 regardless. We will need to search for "logon denied" on stdout.

I'm piping output to tee so it still appears on the tty (usefull if the sqlplus session is interactive, and also for debugging). You can change to redirect directly to the file if you don't need the output displayed.

Try this:

Code:
#! /bin/ksh
#
#########################
# Unix Code Starts here #
#########################
#
LOG_DIR=/app/work/saps/logs
varDate=`date +%d%h%y`
echo 'Please Enter Database Password: '
stty -echo
read db_pass
stty echo
( sqlplus -s user/$db_pass@prd3 2>&1 <<ENDOFSQL
ENDOFSQL ) | tee /tmp/sql_today.err 
 
if grep -q "logon denied" /tmp/sql_today.err
then
    echo 'sqlplus failed!'
    cat /tmp/sql_today.err >$LOG_DIR/sql_err_${varDate}.txt
else
    echo '\n\033[32mConnected !\033[0m'
fi
#rm -f /tmp/apac_sql_today.err
find $LOG_DIR -name "sql_err_*.txt" -mtime +0 -type f;

Try this:

Code:
#! /bin/ksh
#
#########################
# Unix Code Starts here #
#########################
#
LOG_DIR=/app/work/saps/logs
varDate=`date +%d%h%y`
echo 'Please Enter Database Password: '
stty -echo
read db_pass
stty echo
sqlplus -s user/$db_pass@prd3 2>&1 1> /tmp/sql_today.err <<ENDOFSQL
ENDOFSQL
 
if grep -q "logon denied" /tmp/sql_today.err
then
    echo 'sqlplus failed!'
    cat /tmp/sql_today.err >$LOG_DIR/sql_err_${varDate}.txt
else
    echo '\n\033[32mConnected !\033[0m'
fi
#rm -f /tmp/apac_sql_today.err
find $LOG_DIR -name "sql_err_*.txt" -mtime +0 -type f;

---------- Post updated at 03:33 PM ---------- Previous update was at 03:29 PM ----------

Quote:
Originally Posted by saps19
Hi Chubler,
Code:
( sqlplus -s user/$db_pass@prd3 2>&1 <<ENDOFSQL
ENDOFSQL ) | tee /tmp/sql_today.err

I'm getting the following err:
Code:
./test_db_conn.ksh[13]: syntax error at line 13 : `<<' unmatched

...

Or try this:
Code:
(
sqlplus -s user/$db_pass@prd3 2>&1 <<ENDOFSQL
ENDOFSQL
) | tee /tmp/sql_today.err

Make sure the paranthesis after ENDOFSQL {ENDOFSQL )} should be in new line.
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Password database

I am trying to locate a password database for use at work. I have looked at several open source packages but all that I have found are for a single user and we need to allow multiple user access with view restrictions. Does anyone know of a program that fits these requirements? Thanks... (2 Replies)
Discussion started by: thumper
2 Replies

2. Programming

userpw.h AIX ( delete entry from the shadow password database )

HI i need to delete an entry in /etc/security/passwd. can't find a way to do it with userpw.h api ( AIX ). the passwd file i delete like this. Write all entrys to passwd file except the one we are removing. can't find any function that works like getspent / getpwent do in AIX userpw api.... (4 Replies)
Discussion started by: nighter
4 Replies

3. Shell Programming and Scripting

Sample ksh script for copy the data from excel to database table ?

Hi All, I need to convert the data from excel to database table in sybase. Please provide some sample script.. thanks, Royal. (1 Reply)
Discussion started by: royal9482
1 Replies

4. Shell Programming and Scripting

passing database password to isql command in shell script

Hi, I need to connect to DB through my shell script. but I dont want to hardcode my db password in the script. Is there a way to do it? Thanks ---------- Post updated at 07:42 PM ---------- Previous update was at 04:54 PM ---------- :(Guys..please help me with this:( (1 Reply)
Discussion started by: agrawal.prachi
1 Replies

5. Shell Programming and Scripting

Database password appearing in script output

Hi there, This is my first post, so as you have probably guessed I am looking for some help. Currently we have close to 1000 ksh scripts operating on HPUX servers that call either isql or bcp to connect to Sybase databases. Problem being that the db passwords are appearing in the job log... (3 Replies)
Discussion started by: kdk_irl
3 Replies

6. Shell Programming and Scripting

Validate xml agaist xsd is ksh

how do i validate xml agaist xsd is ksh? (1 Reply)
Discussion started by: LiorAmitai
1 Replies

7. UNIX for Dummies Questions & Answers

Launch a URL,validate username and password using wget or curl

Hi All, I want to launch "ex: http://gmail.com" from the cmd window and validate the credentials with username and password, is it possible? I have found something like this "wget --http-user=USER' --http-password=PASSWORD http://gmail.com" am new to this and unable to find a solution, i... (0 Replies)
Discussion started by: harsha85
0 Replies

8. Shell Programming and Scripting

Any Sample ksh script to validate all the database objects

Hi, I need a sample script to validate all the database objects like 1. table structure(columns, datatypes,key contraints if any) 2. synonyms 3. grants 4. indexes ....etc thank you! (2 Replies)
Discussion started by: srikanth_sagi
2 Replies

9. UNIX for Beginners Questions & Answers

Setting config database user and password using sed

Hello everybody, I need to modify 200 files using a patern matching, I would like to do it with sed but it's not working with the following syntax: sed -e 's/DATABASE_PASSWORD.*oldpass/DATABASE_PASSWORD__', 'newpass/g' config.php need to find: define("__DATABASE_PASSWORD__", ... (6 Replies)
Discussion started by: dco
6 Replies
All times are GMT -4. The time now is 08:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy