:not found bash script, mysql dump - bash

Help me please. When I execute .sh
mysqldump -ulogin-ppass --all-databases > dumps/dbs.sql;
I get error message
/home/b/script.sh: 1: /home/b/script.sh:
: not found
but command create file successfully!
As I understand when the sign ; is in the end, error message occurs. Without it error : Directory nonexistent

Try this:
#!/bin/bash
DIR=$(date +%F_%H-%M)
mkdir $DIR
mysqldump -uusername -ppassword --all-databases > $DIR/dbs.sql

Related

How to read .sql file by dictionary on MacOS?

I got error 2 when exec sql file by dictionary
I tried to exec mysql file on Mac OS at this dictionary: "/Users/kato/Desktop/world_mysql_script.sql"
source /Users/kato/Desktop/world_mysql_script.sql;
Then I got this error:
Failed to open file '/Users/kato/Desktop/world_mysql_script.sql', error: 2
Do you have any solution?
1.
Please try to use mysql command.
mysql -u DB_USER -p -h DB_HOST DB_NAME < /Users/kato/Desktop/world_mysql_script.sql

im getting error code 127 while creating jenkins pipeline here is the script

pg_dump -h 10.12.0.4 -U pet--rsmb--prod-l1--usr -w -c -f 2022-08-10t1228z-data.sql
/var/lib/jenkins/workspace/BACKUP-RSMB--POSTGRESQL#tmp/durable-510acc0f/script.sh: 1: /var/lib/jenkins/workspace/BACKUP-RSMB--POSTGRESQL#tmp/durable-510acc0f/script.sh: pg_dump: not found
Your error clearly indicates that the Shell executor cannot find pg_dump command. Either you have not set pg_dump properly in the Jenkins server or you have not added pg_dump to the executable $PATH.

Check lftp status when executing SFTP from shell script

I am using lftp to connect to SFTP server using the below in a shell script.
host=testurl.url.com
user=username
pass=pass
lftp<<EOF
open sftp://${host}
user ${user} ${pass}
cd test/myfolder/
bye
EOF
when executing the above using a shell script, the script exits but I am not sure if a connection is established and I don't see the output of my cd command which I executed within lftp.
Is there a way to output to a log file to see if connection is successful and the output of cd command.
Thank you.
I added a ls to the list of commands and I was able to list the directories
host=testurl.url.com
user=username
pass=pass
lftp<<EOF
open sftp://${host}
user ${user} ${pass}
cd test/myfolder/
ls
bye
EOF

run bash script containing postgresql script failed

I have already create bash script containing sql script (postgresql), but failed.
owner the file : postgres:postgres with 777 (chmod), but when I execute with "./bash1.sh" error: psql: FATAL: role "postgres" does not exist
the bash script:
#!/bin/sh
THE_DATABASE=epolicy
MY_TABLE=hpx_sms
psql ${THE_DATABASE} <<THE_END
SELECT * FROM ${MY_TABLE};
THE_END
how to fix this problem? or any reference? thank you.

psql command is not found in only certain lines in shell scipt

I have a shell script with a psql command to update a Redshift table. It's worked several times in the original spot in the shell script, but when I copied the command into another line in the script, I got an error saying psql: command not found.
Here's some pseudocode of where the psql command has and has not worked:
#start
if [ -f filename.txt ];
then echo 'first area';
psql #has not worked here
else psql ; #has successfully worked here
fi;
psql # has not worked here
#end
I'd just like pointers or suggestions to figure out the behavior of this. Is there any plausible explanation for this to work only in that else statement?

Resources