if statement - Run a shell script with While condition in an infinite loop based on conditions -
I need to create a shell script to enter some indicators / flag files in the directory So, my implementation plan is somewhat like this - say that JOB1 is scheduled to run sometime in the morning, before a request flag (e.g., / dir1 / Dir2 / req_flag_file_directory / req1.req touch) while saying that this work is in progress, so look for source files of the pattern present in the I will have all the details related to the jobs and their flag files whose structure is shown below, on the basis of the request flag, the script should be aware that other criterias should look for this pointer before placing the file: / P> Please tell me how it can be obtained and if you have other suggestions or solutions then There is still some doubt about the contents of the request file, but I think I have come up with a rather simple solution: Although not at all in the infinite loop First it reads the After parsing all the details, the script with the sole purpose of computing the number of files that match the Hope that helps! / dir1 / dir2 / Flag_file_directory based on the request flag received from a shell script in a directory
/ dir1 / dir2 / req_flag_file_directory and the source files in a directory say
dir1 / dir2 / source_file_directory . For this, I need to run a script in an endless loop using the
while condition because I do not know when to make the source files available Will go
file_pattern_YYYYMMDD.CSV (file patterns are different for different jobs) source File directories, if they exist, then calculate the number if the files are If the count is correct, then first remove the request flag for this job and then touch an indicator / flag file in
touch
/ dir1 / dir2 / flag_file_directory . This indicator / flag file will be used as an indicator that source files are present and jobs can continue to load these files in our system.
request_flags | SOURCE_NAME | Job_name | File_pattern | FILE_COUNT | Indicator_flag_file req1.req | Sourcename1 | Jobname1 | File_pattern_1 | 3 | Ind1.ind req2.req | Sourcename2 | Jobname2 | File_pattern_2 | 6 | Ind2.ind req3.req | Sourcename3 | Jobname3 | File_pattern_3 | 1 | Ind3.ind request ** n ** request |. SOURCENAME * * N ** | JobName ** N ** | File_paper _ ** n ** | 2 | IND ** N **. Ind
# / bin / bash DETAILS_FILE = "details.txt" DETAILS_LINES = $ ((`WC -l $ DETAILS_FILE | awk '{$ 1 print}'` `-1)) Banner line (first line) Description =` tail # - $ DETAILS_LINES $ DETAILS_FILE to delete: TR '\ n \ r' '' PID = () IFS = '' waitall () {# P IDS ... # Wait for the children to exit and indicate whether all the 0 came out of the situation Are there. Local errors = 0 while:; Debugging "Balance Processes: $ *" in Paid $ @; Revert to "PID: $ pid" if kill -0 "$ pid" 2> / Dev / null; Then debug "$ pid is still alive." Set - Wait for "$ @" "$ pid" Alief "$ pid"; Then the debug "$ pid exited the zero exit position." And debug "$ pid exited the non-zero exit position." ((++ errors)) has ended (("$ #"> 0)) || Break # Todo: How does this sleep interfere when a child is finished? So $ $ {WAITALL_DELAY: -1} done (errors (== 0))} Debug () {resonant "debug: $ *" & gt; & Amp; 2; } #infinction # to check for matching pattern in the source file # param: req3.req Sourcename3 jobname3 file_pattern_3 1 ind3.ind check () {NOFILES = `$ 2 -find type f | Egrep -c $ 4` if [$ NOFILES -q "$ 5"]; Then echo the "touching file $ 6" Touch $ 6 and "touch $ NOFILES matching $ 4 pattern" free} Echo "Parsing $ DETAILS_FILE file ..." Read -A lines & lt; & Lt; & Lt; "$ {Lines {@}}" for line "$ DETAILS" IFS = '|' Read - an ARRAY & lt; & Lt; & Lt; "$ Line" resonance "line processed. Disposing of job $ {ARRAY [2]} ..." Check $ {ARRAY [@]} and; IFS = '' PIDS = "$ PIDS $!" #echo $ PIDS Wait $ $ {PIDS} Wait
details.txt file according to your example.
file_pattern of each
source_name folder The
check functions, and if the number of files is equal to
file_count , then touches
indicator-flag_file .
Comments
Post a Comment