Batch Commands

Batch Commands

From TeleFlow

Jump to: navigation, search

The following is a list of useful batch command that may be helpful during system development, and for ongoing maintenance.


Contents

Batch Commands

FTP Batch

This command is how you can provide an automated FTP command within Windows batch coding. First, determine the file you want to send. eg.: Backup20080113.sql

Then, create a text file that contain the commands that the FTP will run. eg: FTPgofile.txt

userid
password
cd www
cd backupdir
put Backup20080113.sql
quit

The command structure in the batchfile will look like this:

ftp -s:FTPgofile.txt www.yourwebserver.com

This will logon, get to a directory, and upload the file. A client, could then pick up any missing files by typing

http://www.yourwebserver.com/backupdir/Backup20080113.log

From a browser, the user can right mouse-click and Save-As.


ScanKill

TeleFlow systems, like any high usage systems, tend to create a lot of log files, but disk space can really fill up when voice recordings are a big part of the system. ScanKill is a batch command that has been created to remove old recordings and log files that are no longer relevant.

MySQL Backup

This is the script that backs up a Wiki database. It will copy the database once every n hours. See also MySQL Administration

rem Backup the Wiki Database without taking it down
title MySQL Backup Loop
 
rem Wait until after the work day
rem sleep 10 hours
echo Sleeping 10 Hours
@ping 127.0.0.1 -n 36000 -w 1000 > nul
 
:top
cd "C:\Program Files\MySQL\MySQL Server 5.0\bin"
rem Lets remember 4 days back.
copy x:\WikiData\wikidb.sqlback3 x:\WikiData\wikidb.sqlback4
copy x:\WikiData\wikidb.sqlback2 x:\WikiData\wikidb.sqlback3
copy x:\WikiData\wikidb.sqlback1 x:\WikiData\wikidb.sqlback2
copy x:\WikiData\wikidb.sql      x:\WikiData\wikidb.sqlback1
 
rem Do a dump of the Wiki database.  Put in Hex to keep the SQL dump non-binary.
mysqldump --complete-insert --hex-blob wikidb > wikidb.sql
copy wikidb.sql x:\WikiData
 
rem Sleep for 24 hours
@ping 127.0.0.1 -n 86400 -w 1000 > nul
goto top

Source Code Backup

This command will create a sub-folder in the SaveHistory folder, which will also auto-create. Make sure this backup command does not back up Exes or any other files that can be readily re-created. The whole point is to save disk space.

@echo off&SETLOCAL
 
rem Get this directory
set TFSys=%~dp0%
 
echo *************************************
echo ***BACKUP*** %TFSys%
echo ***DEV DRIVE EDITION - Both TeleFlow and Web
echo *************************************
 
FOR /f "tokens=1-4 delims=/-. " %%G IN ('date /t') DO (call :s_fixdate %%G %%H %%I %%J)
goto :s_print_the_date
 
:s_fixdate
if "%1:~0,1%" GTR "9" shift
FOR /f "skip=1 tokens=2-4 delims=(-)" %%G IN ('echo.^|date') DO (
    set %%G=%1&set %%H=%2&set %%I=%3)
goto :eof
 
:s_print_the_date
rem echo Month:[%mm%]  Day:[%dd%]  Year:[%yy%]
ENDLOCAL&SET mm=%mm%&SET dd=%dd%&SET yy=%yy%
 
 
Set TFDate=TF%yy%/%mm%/%dd%-%Time%
rem TF2005/10/27-14:31:08.67
rem 0123456789_123456789_123
set TFA=%TFDate:~2,4%-%TFDate:~7,2%-%TFDate:~10,2%
set TFH1=%TFDate:~13,1%
set TFH2=%TFDate:~14,1%
set TFM=%TFDate:~16,2%
set TFS=%TFDate:~19,2%
rem Make sure there are no spaces in the time
if "%TFH1%" EQU " " set TFH1=0
 
rem Build the directory
set SaveName=Save%TFA%-%TFH1%%TFH2%-%TFM%-%TFS%
 
if "%1" == "" goto nodesc
set SaveName=Save%TFA%-%TFH1%%TFH2%-%TFM%-%TFS%-%1
 
:nodesc
 
echo Creating: %TFSys%SaveHistory\%SaveName%
 
rem TeleFlow
mkdir %TFSys%SaveHistory\%SaveName%
mkdir %TFSys%SaveHistory\%SaveName%\Tam
copy  %TFSys%*.tap     %TFSys%SaveHistory\%SaveName%
copy  %TFSys%Tam\*.*   %TFSys%SaveHistory\%SaveName%\Tam
 
rem General
copy  %TFSys%*.xml   %TFSys%SaveHistory\%SaveName%
copy  %TFSys%*.res   %TFSys%SaveHistory\%SaveName%
copy  %TFSys%*.ico   %TFSys%SaveHistory\%SaveName%
copy  %TFSys%*.txt   %TFSys%SaveHistory\%SaveName%
 
rem PHP and Web
copy  %TFSys%*.php   %TFSys%SaveHistory\%SaveName%
copy  %TFSys%*.css   %TFSys%SaveHistory\%SaveName%
copy  %TFSys%*.htm   %TFSys%SaveHistory\%SaveName%
copy  %TFSys%*.html  %TFSys%SaveHistory\%SaveName%
copy  %TFSys%*.pas   %TFSys%SaveHistory\%SaveName%
 
 
goto end
 
:error
echo -
echo ERROR
echo -
 
:end

Hints and Tips for Creating Batch Files

Windows Batch Command language is quickly becoming less relevant, but will always be around. This section contains information on how to use some of its more advanced parameter information. If you have complex batch commands that need to be created, we recommend using Perl, which is included in the xampp installer.

To see the following help use

call /? or for /?

Expansion of batch script argument references (%0, %1, etc.) have been changed as follows:

%* in a batch script refers to all the arguments (e.g. %1 %2 %3 %4 %5 ...)

Substitution of batch parameters (%n) has been enhanced. You can now use the following optional syntax:

       %~f1        - expands %1 to a fully qualified path name
       %~d1        - expands %1 to a drive letter only
       %~p1        - expands %1 to a path only
       %~n1        - expands %1 to a file name only
       %~x1        - expands %1 to a file extension only
       %~s1        - changes the meaning of n and x options to
                     reference the short name instead
       %~$PATH:1   - searches the directories listed in the PATH
                     environment variable and expands %1 to the fully
                     qualified name of the first one found.  If the
                     environment variable name is not defined or the
                     file is not found by the search, then this
                     modifier expands to the empty string

The modifiers can be combined to get compound results:

       %~dp1       - expands %1 to a drive letter and path only
       %~nx1       - expands %1 to a file name and extension only
       %~dp$PATH:1 - searches the directories listed in the PATH
                     environment variable for %1 and expands to the
                     drive letter and path of the first one found.
  • In the above examples %1 and PATH can be replaced by other valid values.

Here is an example of how it can manipulates the first parameter.

   @echo off
 
   if not "%1" == "" goto PART2
   rem Specifying full path to real file.
   call %0 C:\WINNT\SYSTEM32\ODBC32.DLL
   rem Specifying file only.
   call %0 ODBC32.DLL
   rem Specifing long file name to a non-existent file.
   call %0 C:\WINNT\REALLYLONGNAME.TXT
   goto END
   :PART2
 
   echo CALLED WITH   : %1
   echo.
   echo Using 'F'     : %~f1
   echo Using 'D'     : %~d1
   echo Using 'P'     : %~p1
   echo Using 'N'     : %~n1
   echo Using 'X'     : %~x1
   echo Using 'S'     : %~s1
   echo Using 'PATH'  : %~$PATH:1
   echo Using 'DP'    : %~dp1
   echo Using 'NX'    : %~nx1
   echo Using 'DPPATH': %~dp$PATH:1
   echo ----------------------------------------------------------
   :END