Pages

Sunday, March 26, 2017

Code Example reprocess_one_file_main.bat: batch calling sqlplus, perl, bash and scp.

===============================
General
===============================
There is a following flow:
main batch is calling several other batch files.
One of the batch files is calling perl program
One of the batch files is calling sqlplus 

===============================
List of files
===============================
reprocess_one_file_main.bat - This is the main bat, calling all others.

convert_one_file.bat
send_scp_mach_one.bat => send_scp_mach.sh
send_file_list.bat               => send_file_list.sh
append_to_file_list.bat    => append_to_file_list.pl
run_sqlplus.bat                  => update_status_in_db.sql

----------------------------------------------
reprocess_one_file_main.bat
----------------------------------------------
ECHO OFF
ECHO.

SET HOME_DIR=D:\ROOT_PATH
SET HOME_DIR_LINUX=d:/ROOT_PATH
REM =======================================================
REM Populate these parameters before running the script!!!
SET FILE_NAME=some_file
SET SEND_FILE_NAME_LIST=%HOME_DIR_LINUX%/sent_file_list/file_list.test
REM =======================================================

ECHO "====================================="
ECHO "Start reprocess_one_file_main.bat"
ECHO "====================================="
ECHO.

ECHO CALL convert_one_file.bat %HOME_DIR% %HOME_DIR_LINUX% %FILE_NAME%
CALL convert_one_file.bat %HOME_DIR% %HOME_DIR_LINUX% %FILE_NAME%

ECHO CALL send_scp_mach_one.bat %HOME_DIR% %HOME_DIR_LINUX% %FILE_NAME%
CALL send_scp_mach_one.bat %HOME_DIR% %HOME_DIR_LINUX% %FILE_NAME%

ECHO %HOME_DIR%\append_to_file_list.bat %HOME_DIR% %HOME_DIR_LINUX% %FILE_NAME% %SEND_FILE_NAME_LIST%
CALL %HOME_DIR%\append_to_file_list.bat %HOME_DIR% %HOME_DIR_LINUX% %FILE_NAME% %SEND_FILE_NAME_LIST%

ECHO %HOME_DIR%\send_file_list.bat
CALL %HOME_DIR%\send_file_list.bat

ECHO %HOME_DIR%\run_sqlplus.bat %FILE_NAME%
CALL %HOME_DIR%\run_sqlplus.bat %FILE_NAME%

ECHO.
ECHO "====================================="
ECHO "Finished reprocess_one_file_main.bat"
ECHO "====================================="
ECHO.

----------------------------------------------
convert_one_file.bat
----------------------------------------------
SET HOME_DIR=%1
SET HOME_DIR_LINUX=%2
SET FILE_NAME=%3

copy %HOME_DIR%\taptext_tap310_converter\processed\%FILE_NAME%.success %HOME_DIR%\taptext_tap310_converter\input\%FILE_NAME%

%HOME_DIR%\taptext_tap310_converter\run_taptext_tap310_converter_local.bat 

----------------------------------------------
send_scp_mach_one.bat
----------------------------------------------
ECHO OFF

SET HOME_DIR=%1
SET HOME_DIR_LINUX=%2
SET FILE_NAME=%3

ECHO .
ECHO "====================================="
ECHO "Start send_scp_mach_one.bat"
ECHO "====================================="
ECHO .

ECHO HOME_DIR=%HOME_DIR%
ECHO HOME_DIR_LINUX=%HOME_DIR_LINUX%

ECHO FILE_NAME=%FILE_NAME%
ECHO send_scp_mach.sh %FILE_NAME%
d:\software\cygwin\bin\bash.exe --login %HOME_DIR_LINUX%/send_scp_mach.sh %FILE_NAME%

ECHO Done
ECHO .

----------------------------------------------
send_scp_mach.sh
----------------------------------------------
scp -Bq /cygdrive/d/ROOT_PATH/taptext_tap310_converter/output/$1 remote_user@IP:/$1

----------------------------------------------
send_file_list.bat
----------------------------------------------
d:\software\cygwin\bin\bash.exe --login /cygdrive/d/MobilkomAutTaps/send_file_list.sh

----------------------------------------------
send_file_list.sh
----------------------------------------------
scp -Bq /cygdrive/d/ROOT_PATH/sent_file_list/file_list.txt remote_user@IP:/REMOTE/PATH/file_list.txt 

----------------------------------------------
append_to_file_list.bat
----------------------------------------------
ECHO OFF

SET HOME_DIR=%1
SET HOME_DIR_LINUX=%2
SET FILE_NAME=%3
SET SEND_FILE_NAME_LIST=%4

ECHO .
ECHO "====================================="
ECHO "Start append_to_file_list.bat"
ECHO "====================================="
ECHO .

ECHO HOME_DIR=%HOME_DIR%
ECHO HOME_DIR_LINUX=%HOME_DIR_LINUX%
ECHO FILE_NAME=%FILE_NAME%
ECHO SEND_FILE_NAME_LIST=%SEND_FILE_NAME_LIST%


perl append_to_file_list.pl %FILE_NAME% %SEND_FILE_NAME_LIST%

----------------------------------------------
append_to_file_list.pl
----------------------------------------------
#! /usr/bin/perl
use File::Copy;
use strict;
use warnings;

#================================
# Input Parameters Start
#================================
my $tap_file_name = shift;
my $SentFileList = shift;

#================================
# main()
#================================
open(textFile,">>".$SentFileList);
print textFile $tap_file_name.";\n";

close(textFile);

----------------------------------------------
run_sqlplus.bat
----------------------------------------------
ECHO OFF

SET FILE_NAME=%1

ECHO .
ECHO "====================================="
ECHO "Start run_sqlplus.bat"
ECHO "====================================="
ECHO .


sqlplus db_user/db_pass@db_inst@update_status_in_db.sql %FILE_NAME%

----------------------------------------------
update_status_in_db.sql
----------------------------------------------
UPDATE SOME_TABLE SET status = 3 WHERE file_name = '&1' AND status <> 3;

COMMIT; 

No comments:

Post a Comment