Score:0

mysqldump error: Cannot open 38: no such file

hk flag

in my ubuntu server I want to do a mysql backup of my database, however I get the following error:

run-backup.sh: 10: run-backup.sh: cannot open 38: No such file

In my home directory I created a sql-backup directory, so I don't know what the error means...

Also is there a way for mysql to not ask to enter mysql passoword since I'm already providing $dbpass inside my shellscript file.

This is my shell script file (changed credentials):

#!/bin/bash
##this script will backup mysql and upload it to google drive 
##directory name
dirname=/home/GabotronES/sql-backups
##database name
database=wooloveapp
##database username
dbuser=GabotronES
##database password
dbpass=xxxxxxxxxxxxxxxxxxxxxxxx
## rclone remote name
remoteName=gabotrones
##spaces folder name
bucketFoldername=sql-backups
##todays date to add to new zip filename
datestring=$(date +\%Y_\%m_\%d_\%H)


mysqldump -u $dbuser -p$dbpass $database | gzip > "${dirname}/${database}-${datestring}.sql.gz"
##wait for 10 seconds
sleep 10

rclone --config=/home/GabotronES/gabotron.conf copy "${dirname}/${database}-${datestring}.sql.gz" $remoteName:$bucketFoldername

exit 0;

Thanks in advance.

hr flag
Does dbpass contain a shell redirection character? something like `dbpass=xxx<38` for example? Regardless, you should quote the RHS of the assignment, like `dbpass='xxxxxxxxxx'`
gabogabans avatar
hk flag
actually yes, the password has <38 at the end... soI should quote the password then, what about the user, do I need to quote it too
Score:1
hr flag

If the line numbering is correct, then it indicates the error is in the assignment statement dbpass=xxxxxxxxxxxxxxxxxxxxxxxx

Because the RHS is not protected by quotes, the shell will try to interpret it. So for example if the password ends in <38 it will try to redirect standard input from a file named 38 in the current directory and (assuming no such file exists) you will get an error like:

$ bash -c 'dbpass=xxxxxxxxxxxxxxxxxxxxx<38'
bash: 38: No such file or directory

(in bash)

$ sh -c 'dbpass=xxxxxxxxxxxxxxxxxxxxx<38'
sh: 1: cannot open 38: No such file

(in sh)

The solution is to make sure you properly quote the string on the RHS of the assignment:

dbpass='xxxxxxxxxxxxxxxxxxxxxxxx'

For similar reasons you should also double quote variable expansions like mysqldump -u "$dbuser" -p"$dbpass" "$database"

For a more thorough discussion (including slightly different rules for other shells) see Security implications of forgetting to quote a variable in bash/POSIX shells

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.