:: File: zip-and-sent-folder.cmd v.1.3.0 docs at the end
@ECHO off
:: set the nicetime var
call GetNiceTime_on_%computername%.cmd
:: go the run dir
cd %~dp0
:: this is the dir containing the batch file
set MyDir=%CD%
for %%A in (%0) do set MyDriveLetter=%%~dA
for %%A in (%0) do set MyPath=%%~pA
for %%A in (%0) do set MyName=%%~nA
for %%A in (%0) do set MyExtension=%%~xA
:: go 4 levels up
for /L %%i in (1,1,5) do pushd ..
:: resolve the 4th dir up
set _DirLevel4Up=%CD%
:: find the BaseDir
set _ProductBaseDir=%_DirLevel4Up%
:: next_line_is_templatized
set _ProductName=morphus
set _ProductDir=%_ProductBaseDir%\%_ProductName%
:: next_line_is_templatized
set _ProductVersion=1.1.8
:: next_line_is_templatized
set _ProductType=dev
:: next_line_is_templatized
set _ProductOwner=ysg
set _EnvironmentName=%_ProductName%.%_ProductVersion%.%_ProductType%.%_ProductOwner%
set _ProductVersionDir=%_ProductDir%\%_EnvironmentName%
:: ECHO MyName %0
:: ECHO MyDriveLetter is %MyDriveLetter%
:: ECHO MyPath is %MyPath%
:: ECHO MyName is %MyName%
:: ECHO MyExtension is %MyExtension%
:: define the project folder to zip and sent as the first cmd argument
set ProjectFolder=%1
for %%A in (%ProjectFolder%) do set ProjectDriveLetter=%%~dA
for %%A in (%ProjectFolder%) do set ProjectPath=%%~pA
for %%A in (%ProjectFolder%) do set ProjectName=%%~nA
:: go the ProjectDriveLetter
%ProjectDriveLetter%
:: go to the project folder
cd %ProjectFolder%
:: build the project name
:: build the zip file
set _ZipFile=%ProjectName%.%computername%.zip
:: go one dir up
cd ..
:: build the zip file path
set _ZipFilePath=%CD%\%_ZipFile%
set _ZipFileTimeStamped=%_ZipFile%.%NiceTime%.txt
:: echo cd is %cd%
:: pause
:: add the files into a package::
zip -r %_ZipFile% %ProjectName%\*
:: PAUSE
::debug echo nicetime is %niceTime%
::DEBUG PAUSE
:: DEBUG echo rename "%cd%\zipFile.zip" %niceTime%.zip.txt
:: DEBUG PAUSE
:: make it a txt file for easier e-mail deleting
rename "%cd%\%_ZipFile%" "%_ZipFileTimeStamped%"
:: the perl script is the same as the file name + the pl extension
set PerlScript=%_ProductVersionDir%\libs\perl\sendEmail.pl
:: define the log file
set MailLogFile=%MyDir%\%MyName%.log
:: define the error log file
set MailErrorLogFile=%MyDir%\%MyName%.error.log
:: the "from" e-mail address
:: set /p FromEmail=Type here the e-mail to send the e-mail from
for /f "tokens=4 delims= " %%i in ('type %userprofile%\gate.csv ^| grep google') do set FromEmail=%%i
:: the "to" e-mail address
:: set /p ToEmail=Type here the e-mail to send the e-mail to
for /f "tokens=4 delims= " %%i in ('type %userprofile%\gate.csv ^| grep google') do set ToEmail=%%i
:: the e-mail subject to use to the message
set MailSubject="%ProjectName% --- %_NiceTime% "
:: define the text file holding the message
set MessageFile=%ProjectFolder%\Mesage.html
:: add the project name and the current time stamp in the message
echo %ProjectName% --- %_NiceTime% > %MessageFile%
:: define the smtp server
:: set SmtpServerAndPort=<<Type here your smtp.domain.com:port>>
for /f "tokens=6 delims= " %%i in ('type %userprofile%\gate.csv ^| grep google') do set SmtpServerAndPort=%%i
echo SmtpServerAndPort is %SmtpServerAndPort%
:: PAUSE
:: define the smtp use to use for authentication against the smtp server
:: set SmtpUser=<<TypeHereYourSmtpUser>>
for /f "tokens=4 delims= " %%i in ('type %userprofile%\gate.csv ^| grep google') do set SmtpUser=%%i
echo SmtpUser is %SmtpUser%
:: PAUSE
:: define the password of the smtp user against the smpt server
:: set SmtpUserPass=<<SmtpUserPass>>
for /f "tokens=5 delims= " %%i in ('type %userprofile%\gate.csv ^| grep google') do set SmtpUserPass=%%i
echo SmtpUserPass is %SmtpUserPass%
:: PAUSE
:: clear the result of the previous runs
:: del /q %MyDir%\*.log
:: del /q %MyDir%\*.html
echo "%_NiceTime%" > %MailLogFile%
echo "%_NiceTime%" > %MailErrorLogFile%
:: Action !!!
:: perl %PerlScript% >%LogFile% 2>%ErrorLogFile%
perl %PerlScript% -v -v -l %MailLogFile% -f %FromEmail% -t %ToEmail% -u %MailSubject% -o message-file=%MessageFile% -s %SmtpServerAndPort% -o message-content-type=html -o tls=yes -o timeout=2 -xu %SmtpUser% -xp %SmtpUserPass% -a %MessageFile% %_ZipFileTimeStamped%
:: Purpose:
:: zip a project and backup it an smpt server having tls support
:: client
:: Requirements:
:: Windows XP or newer
:: perl http://strawberryperl.com/
:: sendMail.pl : http://caspian.dotconf.net/menu/Software/SendEmail/
:: win gnu zip for windows : http://gnuwin32.sourceforge.net/packages/zip.htm
:: GetNiceTime_on_%computername%.cmd to generate time in YYYY.MM.DD hh:mm:ss format
:: access to an stmp server supporting tls
:: Usage
:: Start - Run - type %0 <<FullPathToTheFolderToBackUP>>
:: F:\morphus\morphus.1.1.8.dev.ysg\sfw\cmd\zip\zip-and-sent-folder.cmd F:\morphus\morphus.1.1.8.dev.ysg\sfw\tools\imatica\list-the-failed-tasks-from-today
:: VersionHistory
:: 1.3.0 --- ysg --- Separation of code and configuration, doc update
:: 1.2.0 --- ysg --- Fixed bug of not comrpessing folder on different drive letter
:: 1.1.0 --- ysg --- Added GetNiceTime
:: 1.0.0 --- ysg --- Initial version from previous tools
:: DEBUG
:: PAUSE
No comments:
Post a Comment
- the first minus - Comments have to be moderated because of the spammers
- the second minus - I am very lazy at moderating comments ... hardly find time ...
- the third minus - Short links are no good for security ...
- The REAL PLUS : Any critic and positive feedback is better than none, so your comments will be published sooner or later !!!!