Sqlplus encode password - sqlplus

I have the below line in a batch file.
more myfile.txt | sqlplus user/password#tnsid
Is there any way to encode the password and still have sqlplus understand it in order not to be readable?

Related

grep not finding blank lines on a particular file

I preform the command grep '^$' myfile and receive no results.
In vi you can clearly see it list the following on line 2 of the file. In vi I set number and set list and this is what that line looks like.
2 $
The previous line terminates with a $ too. If I run it without the the ^ it returns every single line like you would expect.
I run the command on other files and it works, but not from files from a particular source. The file is ASCII text, with CRLF line terminators, so are the others.
Not sure what else I can look at on this type of file that would affect these results.
*Looking in notepad++ looking at the hidden characters the problematic has CRLF at the end of the lines blank or otherwise.
The non-problematic one is just LF.
Somewhere in there is the problem just finding it difficult to craft a grep statement that figures this out.
*Took the problematic file and used dos2unix and grep -En '^$' myfile works now. Too bad I can't be editing this file for my ultimate fix.
*In the end this is what worked for this file type.
grep --color=never -n '^[^[:print:]]' myfile

special characters in password in curl command

In my password, there are two special characters are there > and :, when i run curl command it's not working with error:
The system cannot find the file, even i tried escape characters in my password as \> and \:.
Also i did double quotes e.g. curl -u "abc\\sys_account:Tabc>fg:Eh" abc.org
Still I haven't get any luck.
Any help will be much appreciated.
Also it's not working with WithCredentials Pipeline syntax in Jenkins.

psql error when used with username containing at (#) and using URL

I'm trying to connect to my PostgreSQL 11.3 server using CLI (psql). I have a requirement to set password in command line (cannot use environment variable PGPASSWORD).
I'm trying to use an URL to access database like this:
psql postgresql://username#server:password#server.full.name:5432/db_name
As you see, my login contains at (#) in it, e.g. my login name is: username#server.
I get error:
psql: Invalid port number: "password#server.full.name:5432/db_name"
I suppose that psql CLI parses first at (#) as a delimiter between username and server name. Is is a psql CLI bug?
How can I pass such username (containing #) in URL to start psql properly?
Thanks!
Update 1:
My colleague suggested to use %40 instead of colon : between login and password like this:
psql postgresql://username#server%40password#server.full.name:5432/db_name
But this has no effect (I use Windows 10, cmd.exe)
After some investigation, I found a solution (for the benefit of others):
psql postgresql://username%40server:password#server.full.name:5432/db_name
If you start it from cmd or bat file, mask percent sign (%) like this:
psql postgresql://username%%40server:password#server.full.name:5432/db_name

SQLPlus one-line questions

I inherited some sqlplus code that no longer is valid in our Workload Automation tool. It needs to either be converted to a script and called, or a one-line command. I absolutely understand how to do the first (fairly basic). But if I wanted to convert to one line, is my thinking correct?
sqlplus -s myID/pwd <<EOF
define start_date=$start_date;
define end_date=$end_date;
define max_depth=$max_depth;
define min_units=$min_units;
#/app/myapp/sql/forecast
EOF
to convert to one line, is it as simple as:
sqlplus -s myID/pwd < define start_date=$start_date; define end_date=$end_date; define max_depth=$max_depth; define min_units=$min_units; #/app/myapp/sql/forecast
Thanks in advance
Assuming your one line is still be running from a shell script, which the call to sqlplus suggests, you can use a pipe rather than a redirect to pass the commands to SQL*Plus:
printf "define start_date=$start_date\ndefine end_date=$end_date\ndefine max_depth=$max_depth\ndefine min_units=$min_units\n#/app/myapp/sql/forecast" | sqlplus -s myID/pwd
Or perhaps slightly more readably, which you may disagree about:
printf "define start_date=%s\ndefine end_date=%d\ndefine max_depth=%d\ndefine min_units=%d\n#%s" $start_date $end_date $max_depth $min_units /app/myapp/sql/forecast | sqlplus -s myID/pwd
You need line breaks rather than semicolons to separate the define client commands from each other and the #.

Importing mysql procedures generated from mysqldump --routines

I use the mysqldump tool to make copies of my database. The problem is, when I use the --routines parameter to output my stored procedures along with my data, the generated output causes an error when I try to import it.
It goes something like this:
% mysqldump --routines MyDB | mysql MyDB2
(where MyDB2 already exists but is empty)
The error I get is the following:
ERROR 1064 (42000) at line 307: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 23
Everything works correctly if I omit the --routines.
Has anyone else encountered this?
I was able to get this to work by splitting it into two calls:
% mysqldump MyDB | mysql MyDB2
% mysqldump --routines --no-create-info --no-data --no-create-db --skip-opt MyDB | mysql MyDB2
If something's erroring when running the queries in MyDB2, it's best to:
Run mysqldump to save the output to a saved file.
Run the file bit by bit, to identify which part has the problem.
Fix that bit.
I once had a problem like this where I was exporting from an old version of mysql and importing into a newer one, which had declared one of my column names a reserved word. Are your two databases on different servers running different versions of mysql? Or is there some other difference between the databases (e.g. character set)?

Resources