the error is after the
del "C:\backupforalldbs\tpsdatabase\bk_%backuptime%.sql"
Here's the source code:
CLS
SET backuptime=%DATE:~10,4%-%DATE:~7,2%-%DATE:~4,2%-%TIME:~0,2%-%TIME:~3,2%
echo %backuptime%
echo Running dump ...
set 7zip_path=
"C:\xampp\mysql\bin\mysqldump.exe" --host="localhost" --port="3306" --user="jakedean" --password="jakedean" -Q --result-file="C:\backupforalldbs\tpsdatabase\bk_%backuptime%.sql" jakedean
echo Zipping ...
"C:\Program Files\7-Zip\7z.exe" a -tzip "C:\backupforalldbs\tpsdatabase\bk_%backuptime%.zip" "C:\backupforalldbs\tpsdatabase\bk_%backuptime%.sql"
echo Deleting the SQL file ...
del "C:\backupforalldbs\tpsdatabase\bk_%backuptime%.sql"
timeout /t 5
echo Done!
#pause
and here's a print screen of the cmd prompt after executing...
I've tried everything from changing files names, shortening the directory, changing the non caps but nothing has worked... :/
Your problem is that the %backuptime% variable is generating slashes, you should find a way to remove them, since windows doesn't allow files with a slash in it's name. That's what's bugging your command.
List of unsupported characters:
Check the file name in the directory before you attempt to delete it.
I fixed this by replacing the
SET backuptime=%DATE:~10,4%-%DATE:~7,2%-%DATE:~4,2%-%TIME:~0,2%-%TIME:~3,2%
with
SET backuptime=%TIME:~0,2%-%TIME:~3,2%
The date was adding a / which isn't allowed in file names which caused the error. Also the date wasn't setting the correct data, it kept setting 01-02...
The whole .bat file now looks like this
#echo off
CLS
SET backuptime=%TIME:~0,2%-%TIME:~3,2%
echo %backuptime%
echo Running dump ...
set 7zip_path=
"C:\xampp\mysql\bin\mysqldump.exe" --host="localhost" --port="3306" --user="jakedean" --password="jakedean" -Q --result-file="C:\backupforalldbs\tpsdatabase\bk_%backuptime%.sql" jakedean
echo Zipping ...
"C:\Program Files\7-Zip\7z.exe" a -tzip "C:\backupforalldbs\tpsdatabase\bk_%backuptime%.zip" "C:\backupforalldbs\tpsdatabase\bk_%backuptime%.sql"
echo Deleting the SQL file ...
del "C:\backupforalldbs\tpsdatabase\bk_%backuptime%.sql"
timeout /t 5
echo Done!
Related
I have a workflow step that runs this last stage of a shell command in a loop:
|| echo "::error Filename $filename doesn't match possible files" && exit 1 ; done
The exit is triggered appropriately, but the only annotation I see is:
Error: Process completed with exit code 1.
The log shows the entire shell command pipeline and also that same error message, but not my echo'd error.
How do I get my output, including the $filename variable, included?
You have wrong syntax:
echo "::error::Filename $filename doesn't match possible files"
You need to postfix error with ::
Here is a working example of workflow using my suggestion:
https://github.com/grzegorzkrukowski/stackoverflow_tests/actions/runs/1835152772
There must be something else wrong with your workflow if it doesn't work - other command is exiting with code 1 before it has a chance to execute.
I want to launch a particular URL in chrome every day at the same time. How can I achieve this using command line?
There are two ways to do this. The first being from a single command line. You will want to create a new task in Task Scheduler and have it run a command at a desired time. If you wish to use a different browser that supports command lines, be sure to use _ for any spaces in the directory path.
Command line:
SchTasks /Create /SC DAILY /TN "New_Task" /TR "start "C:\Program_Files_(x86)\Google\Chrome\Application\chrome.exe" www.stackoverflow.com" /ST 09:00
The second option is to use a batch file you store somewhere and it will be called to using the SchTasks. Simply create the site1.bat and place it somewhere safe example C:\Windows\My Tasks.
From Batch:
#ECHO OFF
#set Task_Name=Task1
#Set Time=09:00
#set Site=www.stackoverflow.com
schtasks /query /TN "%Task_Name%" >NUL 2>&1
IF %ERRORLEVEL% EQU 0 (goto :EXISTS) ELSE (goto :CREATE)
:CREATE
Set Folder=%~dp0
Set Name=%~nx0
Echo Task does not already exist, creating it now.
SchTasks /Create /SC DAILY /TN "%Task_Name%" /TR "%Folder%%Name%" /ST %Time%
goto :eof
:EXISTS
start "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" %Site%
goto :eof
I normally work with PHP/MySQL. A client wants to send variables from a .bat file - to a remote MySQL - where I will then manipulate them for display etc. I do not know how to connect and send these variables from a bat file in Windows.
I have small .bat file on windows, that simply writes a few variables to a text file.
#echo off
#echo Data: > test.txt
#echo VAR_1=777 >> test.txt
#echo VAR_2=245.67 >> test.txt
The result of the .bat file is a text file test.txt created with various details in it.
I would like the .bat file commands to also:
1) connect to a remote MySQL database
connect -> '8580922.hostedresource.com'
2) save to a basic table on a remote MySQL database:
INSERT INTO `My_Database`.`My_Table` (
`VAR_1` ,
`VAR_2` ,
)
VALUES (
'777',
'245.67'
);
Is this possible?
Is so - how?
I don't have MySQL Installed and I'm not familiar with it but here is a crack at something to try, based on info from the linked page.
REM This needs to be set to the right path
set bin=C:\Program Files\MySQL\MySQL Server 5.6\bin
REM set the host name and db
SET DBHOST=8580922.hostedresource.com
SET DBNAME=MyDatabase
REM set the variables and the SQL
SET VAR_1=777
SET VAR_2=245.67
SET SQL="INSERT INTO `My_Database`.`My_Table` (`VAR_1`,`VAR_2`) VALUES ( '%VAR_1%',
'%VAR_2%');"
"%bin%/mysql" -e %SQL% --user=NAME_OF_USER --password=PASSWORD -h %DBHOST% %DBNAME%
PAUSE
Please try that and post back the resulting error message. There are many reasons that it won't work, but you need to try it to find out.
I'm not sure where test.txt comes into this but it would be a good idea export the whole SQL statement to a text file then use the correct MySQL command line switch to just run the file instead of generating the SQL inside the batch file.
There's a bit more here.
connecting to MySQL from the command line
I have an application that is to be deployed to 1000+ Windows machines. Each machine is in a remote office and is given a Node ID 1-35 and a Branch ID eg. 001122 (unique to each office). I have the install running silently but at one point it asks you to enter the Node ID and Branch ID. I am using the below code in a batch file to allow the engineer running the install to enter the details manually but this is very time consuming and we would prefer to have no user interaction.
We have all the hostnames, IPs, Node ID and Branch ID in one CSV.
My question is, is it possible for the bat file (or another scripting language) to check the IP address or hostname of the pc locate this in the CSV and to parse in the Node ID and Branch ID found in the corresponding rows. How might I go about changing set /p to look at a csv. I am not a coder so am unsure of how to go about reading in a CSV.
Sample of batch file used:
#echo off
setlocal
(set /p NodeId=Enter Node ID:)
(set /p GroupId=Enter Branch ID:)
:: Check that parameter is passed in
if %GroupId%.==. echo WS Group Id required as parameter & GoTo :END
if %NodeId%.==. echo WS Node Id required as parameter & GoTo :END
if %NodeId% GTR 31 echo WS Node Id should be less than 32 & GoTo :END
set GroupId=%GroupId%
set NodeId=%NodeId%
echo Installing Workstation Group=%GroupId% and Node=%NodeId%
Assuming a CSV like the following:
Hostname,IP,NodeID,BranchID
Chef,192.168.0.10,1-35,001122
Secretary,192.168.0.12,1-38,001122
Test,192.168.0.24,1-40,00112
...
this should work:
for /f "tokens=1-4 delims=," %%a in ('type file.csv ^|find /i "%computername%" ') do (
echo Installing Workstation %%a, Group=%%d, Node=%%c with Address %%b
set groupID=%%d
set nodeID=%%c
)
Octave shows echo "octave:#>" before command line in interactive mode where # is the order of the entry. I want to use a program that uses it so I want to cancel that echo. How can I do this?
This is called command prompt. You can set the PS1 to the empty string with:
PS1("")
For more info: https://www.gnu.org/software/octave/doc/interpreter/Customizing-the-Prompt.html