How do I automate oracle DR with script run through putty - oracle

So I am Trying to sync my oracle production server to oracle dr server there is a set of command that I have to run each time to remove transport and apply lag. so fistly i have to login to putty
so to automate that I created an executable
putty.sh
which reads
`putty.exe -ssh servername -l username(oracle) -pw password -m C:/auotomation/dgmgrl.sh(this is a file where my script is safe that I want to run)
the command in dgmgrl.sh file are
#echo off
dgmgrl
"and so on"
i am getting error that bash: line 3: dgmgrl: command not found
I am not getting this error when typing this command manualy
I am getting errors while running dgmgrl;
I am also getting errors while running commands like sqlplus /nolog
but commands like LS and CD are running fine

Related

Executing db2 commands from bash script giving errors?

I am a noob in running db2 commands in the unix environment, so I have been trying to connect to a db2 instance from a bash script. However I get errors here is what my script looks like:
#!/bin/bash
DB2="java com.ibm.db2.clp.db2"
$DB2 "connect to <db2 server here> user **** using ****"
I get a DSNC102I : The option "connect to <db2 server> user **** using ****" specified after the "db2" command is incorrect.
I do not know what to do from here.
Currenty I am able to run an sql script from the same bash script by using
$DB2 -tvf part3.sql where both connection details and sql queries are in the part3.sql file.
Why can't I achieve the same results by writing the sql commands themselves in the bash script.
PS:
I want this since I my bash script is required to accept any db2 instance/ schema to conduct queries as a parameter to the bash script
It looks like you're using the CLP under USS and it is interpreting the connect statement as an option flag instead of a command.
Putting the connect statement and the statements to run in a file at run time should do what you need - this script takes parameters for db2 server, username, and password so you can remove them from part3.sql:
#!/bin/bash
DB2="java com.ibm.db2.clp.db2"
echo "connect to $1 user $2 using $3;" > temp.sql
cat part3.sql >> temp.sql
$DB2 -tvf temp.sql
rm temp.sql
The connect statement is put into a temp file, then the contents of the part3.sql file are copied in and the file is run by the CLP. Finally the temp file is removed.

Command doesn't run from shell script on remote windows machine: Unable to execute command or shell in remote system

I have a Windows Client machine and I would like to invoke a powershell script on that client from my local machine i.e. Mac.
I have ssh on Windows via freesshd.
Also, i need to provide password via script hence I ended up using sshpass.
From my Mac Terminal, while the command:
sshpass -v -p xxx ssh administrator#x.x.x.x "powershell.exe dir"
runs perfectly and returns the content of whatever directory the shell lands in, i am unable the get the same result from inside a shell script.
The simple script is as below:
cmd='sshpass -v -p xxx ssh administrator#x.x.x.x "powershell.exe dir"'
echo `$cmd`
What I get is:
Unable to execute command or shell on remote system: Failed to Execute
process.
I have tried various permutations of " and ' to get the correct command string but to no avail.
What is wrong here?

Execute SSH Script via Command Line and then Close Shell

I am trying to schedule a mysqldump through SSIS and the only way I see possible is through the command line with Putty. My command looks something like this:
putty.exe user#host -pw password -m script.txt
Inside my script is my mysqldump command:
mysqldump -h host -u username -ppassword schema > dump_file.sql
When I test this with a dummy database, it works because the time it takes to complete is less than a minute, so it would run the command, open up a shell, execute the script, and exit the shell after it is done.
My issue now is with a live database, it takes longer and my connection eventually times out and the connection is lost and the shell never closes (even though the dump is successful). So this causes my SQL Server Agent job to be hanging and never ends.
Is there a way that I can run the script and then exit the shell without waiting for it to finish first?
Try running the mysqldump command in background by using &.
nohup mysqldump -h host -u username -ppassword schema > dump_file.sql &

Unable to run psql command from within a BASH script

I have run into a problem with the psql command in my BASH script as I am trying to login to my local postgres database and submit a query. I am using the command in the following way:
psql -U postgres -d rebasoft_appauditor -c "SELECT * FROM katan_scripts"
However, I get the following error message.
psql: FATAL: Ident authentication failed for user "postgres"
This runs perfectly fine from the command line after I appended the following changes to /var/lib/pgsql/data/pg_hba.conf:
local all all trust
host all all 127.0.0.1/32 trust
Also, could this please be verified for correctness?
I find it rather strange that database authentication works fine on the command line but in a script it fails. Could anyone please help with this?
Note: I am using MAC OSX
It might possibly depend on your bash script.
Watch for the asterisk (*) not be replaced with the file names in your current directory. And possibly a semicolon or \g might help to actually send the SQL statement to the database server.

Ssh to remote server through windows batch

Can anyone suggest me how I can use Windows Batch Program to ssh to remote server and then execute shell scripts over there?
Any simple sample example will be good for me to start on this.
Server Name:- ares-ingest.vip.host.com
Username:- uname
Password:- password
Any suggestions will be appreciated as I am new to Windows Batch Program
Update:-
I tried using plink to execute the shell script that I have on my local machine and I always get the error like below, Is there anything wrong I am doing?
C:\PLINK>plink uname#cli.host.com -m email.sh
Using keyboard-interactive authentication.
Password:
Using keyboard-interactive authentication.
Your Kerberos password will expire in 73 days.
sh: HIVE_OPTS= -hiveconf mapred.job.queue.name=hdmi-technology: is not an identifier
Below is the content in my shell script-
#!/bin/bash
export HIVE_OPTS="$HIVE_OPTS -hiveconf mapred.job.queue.name=hdmi-technology"
hive -S -e 'SELECT count(*) from testingtable2' > attachment.txt
try using plink to send your commands over.
Usage: plink [options] [user#]host [command]

Resources