Automatically connecting to OpenVPN with a script - remote-server

I'm setting up an automated e-mail system that pulls queries from a MariaDB database and emails the outputs to my clients. I want these scripts to run daily, but they're being run from a server and I need to connect/log in to OpenVPN to connect to the MariaDB database. Is there a way for me to write a script that will connect to OpenVPN with my credentials so that these queries can be scheduled to run automatically?

Related

Avoid cancel of postgresql script when losing connection to server due to VPN session closing

I'm trying to execute a remote postgresql script by command line (connecting to the server via putty) by using
\i myscript.sql
The problem comes when the script takes several hours to complete and VPN connection to the server (and consequently putty session) close. I can't really control that part because it's a local security policy. The session closing makes the execution of the script to cancel.
Is there an easy way to let the script run in the server regardless I'm still connected to it?
After you putty in use GNU screen or one of its equivalents like tmux before you run psql. This will preserve your session when you get disconnected so you just reconnect to it next time you log in.
You can reduce the TCP keepalive idle time on your client operating system to have the client send “keepalive packets” regularly, which keeps the misconfigured firewall from closing the connection.
Start psql using the connection string syntax:
psql 'host=... port=5432 user=... dbname=... keepalives_idle=60s'

How can I transfer a dumped database in Postgres CLI from my remote server to my remote server or my local machine?

Normally, when I transfer a dumped database from postgres CLI in my local machine, I can simply sftp my_user_name#my_ip remotely from postgres CLI to my local machine without any problems. However, when it comes to my remote server, this seems like I have already connected with my server via ssh connection; thus, when I sudo su - postgres to open up postgres CLI, I cannot use the same technique to
i)sftp my_user_name#my_ip. It said request Connection timed out; I think this may be because they are not in the same WiFI network connection.
ii) or even sftp ubuntu#ec2-xx-xx-xx-xxx.....amazonaws.com. It said my aws ec2 server: Permission denied (public key)
I think this may result from I have made a SSH connection already, so if i sftp again, this will duplicate with the previous SSH connection.
Any idea ?? Please help
it should be simple. I will help you here. Firstly are both machines on same network ? your first comment looks like they are not on same network or we can say they are not connected to each other hence connection timed out. on your second comment; u would need to use pem file to connect to ec2.. Please give all details ; and I will give you commands etc. needed. Also, check security group of destination server if port 22 is open.

Connect remote MongoDB server without SSH

Hi I want to connect to remote MongoDB server without using SSH tunneling(Both the client and server systems will run on windows OS). Is there any way to connect.

SQL Developer doesn't connect using Hostname of my machine

I'm not able to connect to local oracle database from SQL Developer when I'm giving my computer hostname for "Hostname" field in SQL Developer connection.
Database and SQL Developer are running on the same machine.
SQL Developer was able to connect when hostname are replaced with following:
localhost --localhost as hostname is working
127.0.0.1 --This is working as well
192.168.0.5 --Static IP Configured for machine is working
10.10.10.10 --Loopback configured for machine is working
Attached files showing following info:
"Config files details" : hosts, tnsnames.ora, listener.ora, sqlnet.ora
"SQL Developer and Network adapter details" : Network adapters used, Screen shots showing the SQL Developer connection details
My Machine is a standalone home PC, So, it doesn't have any domain name associated with it.
It is configured both loopback and Static-IP and hosts file reflects them appropriately.
My Home Wifi-Router is configured to assign Static-IP to my machine based on MAC-Address.
Resolving this is required because, I have used my computer hostname instead of IP-Address as source connection for some other application (Same machine), which i don't want to modify, as the static IP-Adress might need to be modified later and that would require to go to the other application again and again.
I've tried to delete and create the listener afresh, that didn't work !! Not sure, what's wrong with this Hostname.
Thanks,
Durga.
SQL Developer and Network adapter details
Config files details
Edit: Also, weirdly enough, SQLPlus connects to the host when i give the password directly in connection string. However, it says TNS doesn't know of the service when i don't give password as part of connection string. (Attached the screen shot)
Screenshot showing the behaviour of SQLPlus With/Without password in connection string

PGAdmin III cannot connect AWS RDS

I am trying to connect AWS RDS PostgreSql from PgAdmin 3. I followed the below link
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToPostgreSQLInstance.html
In Security Group, I also added PostgreSQL and All traffic as below
The "publicly accessible" flag was enabled (updated after Mark B's comment)
I got the error from PGAdmin3
Very appreciate for any suggestion
******UPDATE*******
I can connect pgAdminIII to AWS RDS successfully using home wifi, but cannot connect using office wifi.
My concern is:
Was the port 5432 blocked by office wifi?
How can I configure/update the port without impacting to current API?
Note: My current API is working well (CRUD)
Can you can test your connection to a DB instance using common Linux or Windows tools first?
From a Linux or Unix terminal, you can test the connection by typing the following (replace with the endpoint and with the port of your DB instance):
$nc -zv DB-instance-endpoint port
For example, the following shows a sample command and the return value:
$nc -zv postgresql1.c6c8mn7tsdgv0.us-west-2.rds.amazonaws.com 8299
Connection to postgresql1.c6c8mn7tsdgv0.us-west-2.rds.amazonaws.com
8299 port [tcp/vvr-data] succeeded!
Windows users can use Telnet to test the connection to a DB instance. Note that Telnet actions are not supported other than for testing the connection. If a connection is successful, the action returns no message. If a connection is not successful, you receive an error message such as the following:
C:>telnet sg-postgresql1.c6c8mntzhgv0.us-west-2.rds.amazonaws.com
8299
Connecting To sg-postgresql1.c6c8mntzhgv0.us-west-2.rds.amazonaws.com...Could not
open connection to the host, on port 819: Connect failed
If Telnet actions return success, then you are good to go.
If you are trying to access it from a network which is not listed for that port. you need to add inbound rules for those network IPs from AMAZON RDS system
You will also need to set Public accessibility true under Connect & security tab in RDS console.
Read this post.In your security group go to unbound rules and add my ip.
and make sure your database is public.
https://serverfault.com/questions/656079/unable-to-connect-to-public-postgresql-rds-instance