Questions tagged [bash]
The bash tag has no summary.
28 questions
1
vote
1
answer
81
views
Take a backup from specific range
I need to backup the data of a specific table by week and then restore it but without truncate table . This table contains the fechaRegistro
I prepared the following script but I'm not sure about the ...
0
votes
1
answer
239
views
capture deleted rows count in a variable from mysql table using bash script
I am trying to capture the number of deleted rows from mysql table from a bash script using --execute option, and it seems to be not working. I have gone through some questions where it mentions using ...
0
votes
1
answer
55
views
How do I ensure that MySQL is writing out its error log as the correct user?
I have a development Airflow server. It uses MySQL as its database. In the mysqld settings, I have the user set to mysql.
However, the log is being written out as a different user named adm whenever ...
0
votes
1
answer
205
views
Help with creating postgres databases with - in the name
I'm currently trying to script some migration of databases on a server.
As part of this process I will need to create a new database with a similar name to the existing database.
Whilst I have this ...
1
vote
0
answers
63
views
Taking full and incremental backups with authentication in MongoDB
We have a multi-tenant micro-service (it's basically kafka with some bells and whistles). We are using Mongodb to store multi-tenant credentials and kafka data so the authentication is really tight. ...
0
votes
1
answer
1k
views
ORA-19504: failed to create file "bh2jk0h7_1_1"
I want to create a script to get incremental backup of the remote Oracle database every week. I save this command in rman_command.sh and give permission to it:
BACKUP INCREMENTAL LEVEL 0 DATABASE ...
0
votes
1
answer
511
views
Issues using a psql -v variable with jsonb_set
Pretty obscure situation and a couple hours of trying different things with no luck.
I have a bash script which restores a production database backup locally. Part of the script runs some SQL to set ...
0
votes
0
answers
827
views
Escape single quotes when passing command to psql -c
I need to run the following command in a BASH shell:
sudo -u postgres /usr/pgsql-15/bin/psql -c "select count(*) from web_site where web_page like '%something%' " -d 'some_database'
The ...
0
votes
2
answers
302
views
Command line command to read Oracle Database export Success Message In log File
We have several oracle 19c servers with daily exports. I would like to find a way to run a command to read the export log file to find the success message for the day. e.g. I would like to putty into ...
2
votes
1
answer
11k
views
Run PSQL command from bash script
I would like to know how to run \du within a script, and output that to a file.
Something like the following:
# some_script.sh
psql <database connection> & \du > output_of_du.txt
I can ...
0
votes
1
answer
2k
views
I get the error "(psycopg2.OperationalError) FATAL: role "wsb" does not exist", but the user does exits
I am trying connect to my postgress database using SQLAlchemy. I was working fine yesterday (01/27/22). Now I get the following error:
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) ...
1
vote
1
answer
9k
views
Postgres how do return a message if no results for SELECT query
Have been trying to work out how to return a message if the result is empty.
I am running a select statement as below:
select * from maxIDValue where max_value > 1000000 order by max_value desc;
I ...
1
vote
1
answer
2k
views
How to return values from psql to bash with custom session settings
I need to set the datestyle to "dd/mm/yyyy" before calling a procedure and getting it's return value back to bash.
I tried the following:
read return <<< $(psql \
-...
2
votes
2
answers
2k
views
pg_dump hangs in Git Bash but works in Windows command line
I tried to make a backup of a database from Git Bash environment, but the executable does not output anything.
If I specify the filename using the -f flag, a blank file gets created, so the executable ...
0
votes
2
answers
584
views
Connecting to multiple Oracle databases hosted on different machines - Username as common and different password for each database
Environment:
We have ~100 databases hosted on multiple machines. All databases have common username but password is different on every database.
Issue:
How can I read the password and TNS (Service ...
0
votes
0
answers
1k
views
Dump all data to json files
I'm working on a script that has to dump app data from a schema to json files. Here is what I have thus far:
export SCHEMA="citydb"
export DB="kv_db"
export PGPASSWORD=root
psql -...
3
votes
1
answer
1k
views
execute mysqlshell from within a bash script? is it possible?
I am writing a backup script for a database and want to use mysqlshell util.dumpSchemas() utility.
But how on earth can I make it work from within a shell script?
The basic process I have is this:
...
0
votes
1
answer
37
views
Merging one SQL database into another
Currently in my CI I'm completely wiping production db with development db. That was fine for testing but I'm coming to a stage where I need to start merging instead of completely wiping.
Right now ...
0
votes
0
answers
2k
views
Local Postgres Server on Mac Pw Auth Fail
Disclaimer: I am new to MacOs. Haven't found any useful related question.
After successfully installing postgresql 13.2 via homebrew on MacOs 11.2.1 (BigSur) i run into the following problem:
Use ...
7
votes
1
answer
9k
views
How to pass environment variables to a sql file from bash shell (PostgreSQL)
I need to be able to pass environment variables, from a bash shell executing a .sql file using psql.
The psql command I am running is:
su postgres -c "psql -v ON_ERROR_STOP=1 -v dbname=example -v ...
1
vote
1
answer
3k
views
Save output of a Mongo Command to a Variable bash script
I have been writing a script to find and kill slow mongodb queries, how can I store output of db.currentOp() in a variable?
current I am using this but failing
#! /bin/bash
out=""
mongo <...
1
vote
0
answers
936
views
How to simulate slow queries on MongoDB
I need to write a shell script that finds and kills long running mongodb queries, but I don't have access to the database that runs slow queries, how to I simulate running slow queries on my local ...
2
votes
1
answer
1k
views
Why does Postgresql Data directory revert to default after updates/reboots?
I have something that is pretty simple to explain. We have certain server builds as it relates to directories in our CentOS boxes at my company and so to accommodate those, I have a script that ...
0
votes
1
answer
425
views
Insert file content (with white line and special characters ) in bash variable for insert in oracle table with sqlplus
I write this simpe test.ksh scipt:
#!/bin/ksh
TEST=$(cat $1 )
sqlplus -S *****/*****@*****<<- EOF
set define off;
SET SQLBLANKLINES ON;
INSERT INTO DBADOC.TEST
(
"TEST"
)
...
0
votes
0
answers
1k
views
Bash Script Can't Connect to Azure Postgres using ENV Vars - "The Username should be in <username@hostname> format"
I have a bash script that exports ENV vars to use in connecting to an Azure Postgres DB (mydb.postgres.database.azure.com). For the user portion of that specifically it looks like this:
export PGUSER=&...
2
votes
2
answers
3k
views
Could not find a "psql" to execute
I have a bash script that run on a Linux (AWS Centos) server. There's an odd, but annoying warning message that pops up in the stdout whenever the script executes psql: could not find a "psql&...
0
votes
1
answer
182
views
How to quote a SQL*Plus identifier in a bash script?
I get "ORA-00904: "MEMORY_TARGET": invalid identifier" no matter how I try to quote the identifier in the following command:
MEMORY_TARGET=$(su - orat01 -c " echo 'select ...
6
votes
5
answers
37k
views
What does "psql: /usr/pgsql-11/lib/libpq.so.5: no version information available (required by psql)" actually mean?
I have a question regarding following output:
[nikola@192 ~] $ sudo su - postgres
[postgres@192 ~] $ psql dvdrental postgres
psql: /usr/pgsql-11/lib/libpq.so.5: no version information available (...