This is an example, of creating a scheduled task, on Windows, that would do ftp files to another server.
Flow
1. Get File from Linux server
2. Move it to Windows
3. Handle Files (get last file, delete old files, etc)
4. Send mail, using blat utility
Files
A. main_awr_daily.bat - The main script. Call all other scripts one after another.
B. get_awr_report.bat using ftp_daily_awr_cmd.ini - Get file with ftp from Linux server.
C. delete_old_awr_files.bat - Delete old files from Windows server.
D. mail_report_main.bat - Send the report with blat utility.
main_awr_daily.bat
ECHO OFF
SET SERVER=some.server.com
SET USER=user
SET STEP=get_awr_report.bat
ECHO Calling %STEP%
call get_awr_report.bat %USER% %SERVER% ftp_daily_awr_cmd.ini
ECHO Finished %STEP%
ECHO.
SET STEP=delete_old_awr_files.bat
ECHO Calling %STEP%
call delete_old_awr_files.bat J:\Functionality\AWR\Files AWR_*_Daily* 10
ECHO Finished %STEP%
ECHO.
SET STEP=mail_report_main.bat
ECHO Calling %STEP%
call mail_report_main.bat J:\Functionality\AWR\Files AWR_*_Daily* "AWR Daily Report" mail_awr_daily_header.txt
ECHO Finished %STEP%
ECHO.
SET USER=%1
SET SERVER=%2
SET PARAM_FILE=%3
sftp -b %PARAM_FILE% %USER%@%SERVER%
ftp_daily_awr_cmd.ini
lcd J:\Functionality\AWR\Files
cd /starhome/iu/AWR_FILES/files
mget AWR*Daily*
bye
delete_old_awr_files.bat
ECHO OFF
SET HOME_DIR=%1
SET FILES_FILTER=%2
SET RETENTION_DAYS=%3
REM Delete files older than 10 days
forfiles /P %HOME_DIR% /M %FILES_FILTER% /C "cmd /c del @file" /D -%RETENTION_DAYS%
REM For test
REM goto FINISH
REM :FINISH
REM pause
ECHO OFF
SET WORK_PATH=%1
SET FILE_FILTER=%2
SET MAIL_SUBJECT=%3
SET MAIL_BODY=%4
ECHO Looking for Last File in %WORK_PATH%\%FILE_FILTER%
for /f "tokens=*" %%i in ('dir %WORK_PATH%\%FILE_FILTER% /b/a-d/od/t:c') do set LAST_FILE=%%i
ECHO Last File: %LAST_FILE%
for %%i in (%LAST_FILE%) do set LAST_FILE_NAME=%%~nxi
call mail_report.bat %WORK_PATH%\%LAST_FILE% %LAST_FILE_NAME% %MAIL_SUBJECT% %MAIL_BODY%
SET SOURCE_FILE=%1
SET SEND_FILE=%2
SET SUBJECT=%3
SET MAIL_BODY=%4
ECHO copy %SOURCE_FILE% %SEND_FILE%
copy %SOURCE_FILE% %SEND_FILE%
echo about to mail file %SEND_FILE% -to to_userA@domain.com, to_userB@domain.com -i from_user@domain.com -subject %SUBJECT%
blat %MAIL_BODY% -to to_userA@domain.com, to_userB@domain.com -i from_user@domain.com -subject %SUBJECT% -attacht %SOURCE_FILE%
sleep 2
del %SEND_FILE%
mail_awr_daily_header.txt
Hi,
Please see attached Daily AWR Report.
No comments:
Post a Comment