Mysqldump simple batch issue - batch-file

I am trying to write a simple batch file to run a MySqlDump. I created a new file in notepad, pasted the text below, and then saved it as a bat file. However when I attempt to run this in command prompt the screen pops up right away and then goes away just as fast. If I run these commands manually in command prompt it works as expected.
This is my first bat file I have created so I'm guessing I am doing something wrong? In looking at similar issues in StackOverflow the code below appears to be what is suggested so I'm confused why this isn't working?
cd C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin
mysqldump --user=xxx --password=xxx --all-databases --single-transaction > C:\Users\JMaze\Desktop\nSite\MySQL Backup\bk.sql

Adding the quotes to each of the file paths appears to have fixed the issue. The final code looks like this:
cd "C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin"
mysqldump --user=xxx --password=xxx --all-databases --single-transaction > "C:\Users\JMaze\Desktop\nSite\MySQL Backup\bk.sql"

Related

Writing Batch file that monitors a certain web page's status

The issue
I am trying to create a batch file that will execute the following two commands:
cd /some/path
dotnet run
that produces the following output:
It starts my localhost server.
Trying To Accomplish
What I would like to do is, put those two commands in a batch file and automatically open Chrome to the server address, HOWEVER, the dotnet command takes some time to finish. So somehow, I would have to keep monitoring localhost to see if it is available.
Any help would be appreciated. Although opening a CMD window, typing those 2 commands, and waiting a minute isn't all that much of a problem, it sure would be nice to just click on a batch file.
Thank you.
You can create a batch file like this code :
#echo off
Set "ApplicationPath=%UserProfile%\source\repos\PruttPos\PruttPosSystem\"
CD /D "%ApplicationPath%"
dotnet run
Start "Chrome" Chrome.exe "http://localhost:5000"
pause

Run multiple lines from .bat file

I'm trying to get a bat file together and not sure how to run multiple cmd lines through the .bat.
Objective: I want to be able to click on this .bat file to open cmd prompt, then to find a "folder" in the directory, rename the "Folder" then move the location of the folder then find a existing Folder and put it in the same directory.
Problem: i know how to run these cmds in the prompt without an issues.
So far this is what i have:
#echo off
start cmd.exe /k cd %AppData%\Microsoft\Network\Connections
#echo off
and then just write your commands its that simple
A .bat file is executed in a terminal window automatically, you don't need to call cmd.exe or anything like that.
Every single line you write in the .bat file is going to be executed one by one, so you just need to write multiple lines with all the instructions and then you can double click on your new file to run the script.
If you are not familiar with Windows commands for the terminal, you can find more info on the web about how to find a folder, rename it, etc. There are many things you can do by command line and this is not the right place to explain how to use them.

Reading %0 as %0 in CMD

I think this is a pretty basic doubt but I could not find the solution myself. What I am trying to do is to create a .bat file in order to automate a data upload process. But the command to be passed in .bat file has to have database password which unfortunately has '%0' in it. So, when I run it, cmd reads it as the file name instead, causing it to run into an error. So, can we write this in a way cmd reads '%0' as it is and doesn't change it to filename?
Without seeing your code, it's guessing ...
Probably you are using something like
mysql -u root -p secret%0
Then you can fix it by doubling the percent sign
mysql -u root -p secret%%0

Batch Script responds with "Error opening script file" when opening FTP file

I want to use a Batch file to upload files from a folder on my computer.
When I call the FTP Script to do the upload:
FTP -v -i -s:ftp.txt
or
FTP -v -i -s:c:\path\to\file\ftp.txt
Neither of those works, and instead
Error opening script file: ftp.txt
is returned.
Strange thing is, that the exact same script is being executed without problems on another computer.
Opening the batch file with admin-rights does not help. I'm running Windows 10.
Edit: The ftp.txt looks like this:
open ##host##
##user##
##password##
lcd c:\local\path\
cd path/on/server/
binary
mput "*.xxx"
disconnect
bye
Make a new, empty file with echo >ftp.test and try with that file.
If that gives you the same error, you'll need to look at your execution environment (look at set and the process owner of cmd.exe). It's also possible that the ftp command is being run as a user that doesn't have access to that file.
If you don't get an error then it's probably either a file-permissions or special-character issue with ftp.txt. Retyping the same content into a different file will get around those issues. Remember not to copy/paste because you could accidentally copy invisible special characters that you're trying to avoid.
I would like to add to this conversation since there have been a lot of views and no solution. I had the same response and it wasn't a permissions issue. It was also no the text file that was the issue because it never technically reached the text file. It was the path to the text file. The following for me didn't work. I had to put quotations around the path even though there were no spaces to confuse the command line.
What you tried:
FTP -v -i -s:c:\path\to\file\ftp.txt
What I tried and worked. (I didn't need to use -v, mine works without it)
FTP -i -s:"c:\path\to\file\ftp.txt"
Running the file acted normal for me. My issue was trying to run the batch file through Windows Task Manager. Somehow, this was causing it to lose the text file somehow. I hope this helps anyone else who reads this thread.
I had to put the .txt file path in the "Start In" section for it to work in Windows Task Manager. No problems since.

mysqldump batch script runs but leaves empty file

I have made a simple batch script to back up a database, however when it runs it creates a empty file. This batch script is located in the same folder where mysqldump.exe is located. Following code:
#ECHO off
start /wait mysqldump.exe -u user -p "password" database > "Z:\sql-backup\"database-backup.sql
Any help would really help. New to Batch scripting.
I had used the below commands in batch file and it has worked properly.
First of all you should goto bin directory and issue the below mentioned mysqldump command. The same you can mention in the batch file as it is.
cd C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin
mysqldump -uroot -ppassword database > "C:\ProgramData\MySQL\MySQL Server 5.6\Data\"Database_bkp.sql

Resources