Bash script problem "No such file or directory"
This part of my CentOS bash script fails:
Code:
echo "Proceed? y or n" Code:
Proceed? y or n The "No such file or directory" is baffling. I have tried everything I could think of, such as putting in full paths and putting quotes around $STR. All the files exist, and if the $STR text is run from the command line it runs fine. What could the trouble with the script be? |
What input are you giving this script? Parameters?
Well, anyway, my guess is going to be: Code:
echo "Proceed? y or n" |
Here's the whole script, again edited for security.
Code:
#!/bin/bash |
The above will work.
Are you trying to accomplish something else that my fix doesn't take into account? |
I don't understand your fix. Root is not the owner of the database in question.
I am simply trying to do this within a shell script: Code:
mysql -uMyUser -ppppppp databasename < dumpfile.sql http://php.about.com/od/learnmysql/s...l_backup_2.htm or http://www.techiecorner.com/31/how-t...sql-dump-file/ It works fine from SSH command line but I know from other scripting attempts that I can't get mysql to run from within a script. I do not understand why this is. |
Quote:
Code:
/bin/zcat $1 | /usr/bin/mysql -u MyUser -ppppppp $2 Here is the code i used locally on my server: Quote:
Quote:
|
Same old same old.
Restoring. /bin/zcat mike_forum_110321-0100.sql.gz | /usr/bin/mysql -uMyUser -ppppppp test test.sh: line 30: /bin/zcat mike_forum_110321-0100.sql.gz | /usr/bin/mysql -uMyUser -ppppppp test: No such file or directory (user and password edited here for security) I better go ask the MySQL people I suppose. Asked here bcause I've gotten so much great help here in the past. But this seems to be a stumper. |
Quote:
And,.. have you checked to be sure that this file,.. is in the directory you are running this from? Output from this script working. Code:
[root@sandbox-charlie ~]# cat go.sh |
I've tried that, also tried putting space after -p, but makes no difference. I think you are guessing? Sort of reassuring that it baffles someone else.
I posted at http://forums.mysql.com (has to wait for moderation in order to show up there) Quote:
|
Wait.
Are you changing your script at all? This should be the whole new script. All by itself. Once you see that it works, you can incorporate it into your old script. Code:
echo "Proceed? y or n" |
My script has the full path for the .sql.gz file.
STR="/bin/zcat /home/mike/backups/$1 | /usr/bin/mysql -u MyUser -p pppppp $2" Here's the output of your cmds: [mike@www bin]$ which mysql;which zcat;pwd;ls -alh test.sh;ls -alh /home/mike/backups/*.sql.gz /usr/bin/mysql /bin/zcat /home/mike/bin -rwxrwxrwx 1 mike mike 726 Mar 30 14:53 test.sh -rw-r--r-- 1 mike mike 1.1M Sep 13 2010 /home/mike/backups/ibf_skins_09-13-10.sql.gz -rw-r--r-- 1 mike mike 664M Mar 21 01:03 /home/mike/backups/mike_forum_110321-0100.sql.gz -rw-r--r-- 1 mike mike 667M Mar 22 01:03 /home/mike/backups/mike_forum_110322-0100.sql.gz -rw-r--r-- 1 mike mike 668M Mar 23 01:03 /home/mike/backups/mike_forum_110323-0100.sql.gz -rw-r--r-- 1 mike mike 668M Mar 24 01:03 /home/mike/backups/mike_forum_110324-0100.sql.gz -rw-r--r-- 1 mike mike 668M Mar 25 01:03 /home/mike/backups/mike_forum_110325-0100.sql.gz -rw-r--r-- 1 mike mike 668M Mar 26 01:03 /home/mike/backups/mike_forum_110326-0100.sql.gz -rw-r--r-- 1 mike mike 668M Mar 27 01:02 /home/mike/backups/mike_forum_110327-0100.sql.gz -rw-r--r-- 1 mike mike 668M Mar 28 01:03 /home/mike/backups/mike_forum_110328-0100.sql.gz -rw-r--r-- 1 mike mike 666M Mar 29 01:03 /home/mike/backups/mike_forum_110329-0100.sql.gz -rw-r--r-- 1 mike mike 664M Mar 30 01:03 /home/mike/backups/mike_forum_110330-0100.sql.gz -rw-r--r-- 1 mike mike 1.1M Sep 8 2010 /home/mike/backups/skin_tables_09-07-10.sql.gz [mike@www bin]$ I don't understand your script. You are making a dump. I already have many dumps. :) |
Quote:
Code:
STR="/bin/gunzip < '/home/mike/backups/$1' | /usr/bin/mysql -uMyUser -ppppppp '$2'" |
Well, that at least gives me a different error. :D
Get invalid option if $STR is invoked without quotes. Get "No such file.." if it has quotes. Code:
echo "Proceed? y or n" Restoring. /bin/gunzip < '/home/mike/backups/mike_forum_110321-0100.sql.gz' | /usr/bin/mysql -u whoever -p xxxxxx 'test' /bin/gunzip: invalid option -- u gunzip 1.3.5 |
Quote:
Quote:
Code:
eval "$STR" |
If I use zcat,
Restoring. /bin/zcat '/home/mike/backups/mike_forum_110321-0100.sql.gz' | /usr/bin/mysql -u whoever -p xxxxx 'test' test.sh: line 29: /bin/zcat: No such file or directory [mike@www bin]$ Where would that eval $STR go? When I did this: Code:
STR="/bin/zcat '/home/mike/backups/$1' | /usr/bin/mysql -u mike_forum -p sKeYzY4g '$2'" Code:
/bin/zcatp '/home/mike/backups/mike_forum_110321-0100.sql.gz' | /usr/bin/mysql -u whoever -p xxxxxx 'test' |
(Check the commands in your previous post, please. I think you'll want to edit them.)
Quote:
Quote:
Code:
/bin/zcat '/home/mike/backups/mike_forum_110321-0100.sql.gz' | /usr/bin/mysql -u whoever -p xxxxxx 'test' |
Good question!
This works on command line: Code:
/bin/gunzip < /home/mike/backups/mike_forum_110321-0100.sql.gz | /usr/bin/mysql -uGeorge -pxxxxx test Single quotes were in response to http://www.linuxquestions.org/questi...4/#post4308900 |
My son pointed out that even though echo -e "$STR" looks fine, $STR does not necessarily look good to the command processor. He suggested this:
Code:
if (test "$reply" == "y"); then Thanks to all of you for taking an interest. :newbie: |
Surprising fact
I got to thinking more about this. My original script didn't work, but this does work:
Code:
STR="/bin/gunzip < /home/mike/backups/$1 | /usr/bin/mysql -uUser -pxxxx + STR='/bin/gunzip < /home/mike/backups/mike_forum_110322-0100.sql.gz | /usr/bin/mysql uUser -pxxxx test' + eval /bin/gunzip '<' /home/mike/backups/mike_forum_110322-0100.sql.gz '|' /usr/bin/mysql uUser -pxxxx test ++ /bin/gunzip ++ /usr/bin/mysql uUser -pxxxx test The 'eval' suggestion from Nominal Animal was right on, but when I tried it out it got tangled with a 'zcat' (which didn't work). Thanks and apologies, Normal Animal. |
Quote:
http://linuxdevcenter.com/pub/a/linux/lpt/08_10.html Quote:
|
You are also doing in 3 lines, what can be done in 1.
|
Quote:
|
As i said before, when I re-wrote the part that was breaking...
Code:
STR="/bin/zcat '/home/mike/backups/$1' | /usr/bin/mysql -u username -p password '$2'" Code:
/bin/zcat $1 | /usr/bin/mysql -u MyUser -pppppp $2 Good luck and Regards. |
Quote:
I got incompatible suggestion mixed up together and didn't absorb your very helpful http://www.linuxquestions.org/questi...4/#post4308837 Thanks! |
All times are GMT -5. The time now is 09:11 AM. |