I'm using Git Bash on Windows 10. I would like to import a SQL file to be run in my PostGres 12 local database. I tried the below
$ PGPASSWORD=$DB_PASSWORD psql -U${DB_USER} $DB_NAME < scripts/my-script.sql
stdin is not a tty
When I look in my database, the script hasn't been run, which leads me to believe the error message is telling me why, except I'm not sure what it means or how to fix it.
Don't use redirection on Windows (in general, not just in "git-bash").
Pass the script file using the -f parameter:
PGPASSWORD=$DB_PASSWORD psql -U${DB_USER} -f scripts/my-script.sql $DB_NAME
I have the following bash script:
#!/bin/bash
set command "sqlplus -s user/password#tns"
ssh -t test#192.168.94.139 $command
Now, I want to run te following sql script (which is on the other device I'm accessing):
/usr/mikael/myfile.sql
How is the best practice to run the script from that path?
I've seen a suggestion to add "/usr/mikael/myfile.sql" to the end of the command, as :
set command "sqlplus -s user/password#tns /usr/mikael/myfile.sql"
Is that really good? (I'm working on a prod environment and don't want to mess with it).
Thanks.
set does not do what you think it does. Use
command="sqlplus -s user/password#tns #/usr/mikael/myfile.sql"
I want to run a COPY command on my Cassandra cluster (v3.0.9).
In case my shell exits, how can I later on list running commands, get their status and possibly kill/stop it?
Create a cql file with your COPY command
Run it through cqlsh using -f flag (cqlsh -f ) with nohup. Details here.
Then it will be available to ps and kill.
This code SSH's and then runs a tail command on a remote hots. I would now like to pass that tailed data into a mysql database using a local script called insertPerfmon.sh.
How do I pass data generated in a ssh session into the local shell script insertPerfmon.sh. The local shell script is going to send data to the database. However, I need to get it there first.
( ssh -nq -o StrictHostKeyChecking=no \
-i $PEM_PATH/$PEM_FILE $USER#${host} -p $REMOTE_PORT \
tail -n 5 $REMOTE_HOME/data/PerfMon* |insertPerfmon.sh)
If insertPerfmon.sh is:
#!/bin/bash
mydata=$(cat)
echo $mydata
# process & send $mydata to database
The following should work:
<your_ssh_command> | bash insertPerfmon.sh
I want to run multiple commands automatically like sudo bash, ssh server01, ls , cd /tmp etc at server login..
I am using Remote command option under SSH in putty.
I tried multiple commands with delimiter && but not working.
There is a some information lacking in your question.
You say you want to run sudo bash, then ssh server01.
Will sudo prompt for a password in your remote server?
Assuming there is no password in sudo, running bash will open another shell waiting for user input. The command ssh server01 will not be run until that bash shell is exited.
If you want to run 2 commands, try first simpler ones like:
ls -l /tmp ; echo "hi there"
or if you prefer:
ls -l /tmp && echo "hi there"
Does this work?
If what you want is to run ssh after running bash, you can try :
sudo bash -c "ssh server01"
That is probably because the command is expected to be a program name followed by parameters, which will be passed directly to the program. In order to get && and other functionality that is provided by a command line interpreter such as bash, try this:
/bin/bash -c "command1 && command2"
I tried what I suggested in my previous answer.
It is possible to run 2 simple commands in putty separated by a semicolon. As in my example I tried with ls and echo. The remote server runs them and then the session closes.
I also tried to ssh to a remote server that is configured for not asking for a password. In that case, it also works, I get connected to the 2nd server and I can run commands on it. Upon exit, the 2 connections are closed.
So please, let us know what you actually need / want.
You can execute two consecutive commands in PuTTY using a regular shell syntax. E.g. using ; or &&.
But you want to execute ssh server01 in sudo bash shell, right?
These are not two consecutive commands, it's ssh server01 command executed within sudo bash.
So you have to use a sudo command-line syntax to execute the ssh server01, like
sudo bash ssh server01