Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi All,
I am trying to check the argument passed with the existing users in the database. If matches then message "username matches" else "Username Mismatch". Below is the script i am trying and it always throws "Username Mismatch".
/ora/sw/app/oracle/product/11.2.0.3/bin/sqlplus -s "/ as sysdba" << EOF >> spool /tmp/users.log
column username for a25;
column account_status for a33;
select username,account_status from dba_users where account_status='OPEN' order by 1;
spool off
exit
EOF
if [ `echo $2 |grep -F "/tmp/users.log"` ]; then
echo "UserName Matches"
else
echo "UserName Mismatch"
fi
in your database results. I don't see any reason to append each db query to past results.
Rather than comparing, why not just have you script print exactly what your db is returning, so that you can be sure that what you are trying to compare makes sense.
I'm assuming your DB returns a one-string username.
I am not clear here.
My requirement is when a username is passed through shell script then it has to check with database and throw messages accordingly.
if [ `echo $1 |grep "$dbname"` ]; then
echo "DB Name Matches"
else
echo "DB Name Mismatch"
fi
/ora/sw/app/oracle/product/11.2.0.3/bin/sqlplus -s "/ as sysdba" << EOF >> spool /tmp/users.log
set echo off
set lines 100
set pagesize 0
#set heading off
#set feedback off
set TERMOUT off
column username for a25;
column account_status for a33;
select username,account_status from dba_users where account_status='OPEN' order by 1;
spool off
exit
EOF
if [ `echo $2 |grep -F "/tmp/users.log"` ]; then
echo "UserName Matches"
else
echo "UserName Mismatch"
fi
Early on, issue an `echo $#` see whether the number of arguments is what you expect and follow it up with and `echo $2` before assigning $2 to Table_owner
Add a wc -l and check for numeric equals thus:
Isn't
Quote:
if [ `echo $Table_owner |grep -F "/tmp/users.log" | wc -l` -ge 1 ]; then
echo "UserName Matches"
else
echo "UserName Mismatch"
fi
Why the -F flag? I always thought that it forces an exact match for the full length of the field (25 in your case). So you should pad-right $2 with spaces to make 25 bytes.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.