Continue Execution Based On List


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Continue Execution Based On List
# 1  
Old 01-23-2014
Java Continue Execution Based On List

Hi all.

I have a script like this
Code:
function check_filesize {
filesize_1="$(ls -la "$1"|awk '{ print $5 }')"
sleep 123
filesize_2="$(ls -la "$1"|awk '{ print $5 }')"
if [ $filesize_1 -eq $filesize_2 ]
then
echo "OK"
else
echo "NOT OK"
sleep 1234
check_filesize $1
fi
}

function check_TR {
chk="$(tail -1 $1|grep TR)"
if [ "$chk" != "" ]
then
recnum="$(echo $chk| sed 's/.*|//')"
else
recnum_tmp="$(wc -l "$1"|awk '{ print $1 }')"
recnum="$(echo $recnum_tmp-1|bc)"
fi
echo $recnum
}

function CMLT_Report {
script="$1"
report="$2"
procedure="$3"
file_dir="$4"
file_size="$(ls -la "$2"|awk '{ print $5 }')"
recnum="$(check_TR $2)"
created="$(ls -la "$2"|awk '{ printf "%s,%02i,%s\n" , $6, $7, $8 }')"
remarks="$5"
frequency="$6"
}

function CMLT_Report_2 {
pattern=$1
script=$2
procedure=$3
folder=$4
frequency=$5
for file in $pattern
do
   check_filesize $file
   CMLT_Report "$script" $file "$procedure" "/dbfs_direct/FS1/cmlrpt/" "$folder" "$frequency"
   sh /dbfs_direct/FS1/MIE/script/CAMELOT_REPORTING_LOG.sql $script $report $procedure $file_dir $file_size $recnum $created $remarks $frequency
done
}

CMLT_Report_2 "TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_*.csv" "10.41.54.62/dbfs_direct/FS1/script/run_custom_t.sh" "SP_RPT_FIN_ACC_CONSOL" "Camelot-Financial" "DAILY"

But I want to extend the script in such a way that only proceed if the $pattern belongs to a list (inside file named list.txt)

For example let's say the list contains
Code:
TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_20130414.csv
TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_20130415.csv
TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_20130416.csv
TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_20130417.csv
TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_20130418.csv

So when reading the file pattern
Code:
TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_20130412.csv - NOT PROCEED
TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_20130413.csv - NOT PROCEED
TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_20130414.csv - Proceed
TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_20130415.csv - Proceed
TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_20130416.csv - Proceed

So where do I start?

Thanks for helping.

Thank you.
# 2  
Old 01-23-2014
Shooting a big piece of code and waiting for people to spend their time to reverse engineer it is not the best way to encourage people to answer.

Please take the time to explain what you have and what you are trying to achieve, even if you already provided the code. Thanks
This User Gave Thanks to ctsgnb For This Post:
# 3  
Old 01-23-2014
Quote:
Originally Posted by ctsgnb
Shooting a big piece of code and waiting for people to spend their time to reverse engineer it is not the best way to encourage people to answer.

Please take the time to explain what you have and what you are trying to achieve, even if you already provided the code. Thanks
Thanks for your feedback.

Ok, let's make it simple..

I have one function
Code:
function CMLT_Report_2 {
pattern=$1
for file in $pattern
do
   echo $file >> pass.txt
done
}

So, to call the function

Code:
CMLT_Report_2 "TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_*.csv"

But I only want it to be executed ONLY IF the file_name belongs to this text file named list.txt containing
Code:
TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_20130414.csv
TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_20130415.csv
TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_20130416.csv
TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_20130417.csv
TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_20130418.csv

In other words, I don't want the function to be executed (or break the loop) if the file_name e.g. TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_20130412.csv or TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_20130413.csv

Thank you.
# 4  
Old 01-23-2014
You could of course read list.txt and match that against every $file, but maybe you could try it the other way around:
Code:
while read file
do
  case $file in
    ($pattern) [ -f "$file" ] && echo "$file"
  esac
done < line.txt > pass.txt


Last edited by Scrutinizer; 01-24-2014 at 04:11 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 01-23-2014
So you have a list of file names, a directory full of files, and the intersection of both must match a pattern. It may be a bit tedious to find out the optimum way to boil that down to the actual set of files to be worked upon. Scrutinizer has provided one example; try this as an alternative:
Code:
ls $(grep TM_ICP_EDW_FIN04-ACCOUNT_CONSOL_.*\.csv list.txt) >pass.txt 2>/dev/null

Watch out - grep takes a regex, not a shell pattern!
This User Gave Thanks to RudiC For This Post:
# 6  
Old 01-24-2014
Thanks a lot Scrutinizer and Rudic.

Scrutinizer solution works as expected, thanks.

But actually the real situation is, that CMLT_Report_2 would call another function called CMLT_Report_1. In other words...

Code:
function CMLT_Report_1 {
report=$1
for file in $report
do
   echo $file >> pass.txt
done
}

Code:
function CMLT_Report_2 {
pattern=$1
for file in $pattern
do
   CMLT_Report_1 $file
done
}

Of course the original function is as posted in post #1, but the concept is like that.

Thanks for helping guys.

---------- Post updated at 03:06 PM ---------- Previous update was at 09:55 AM ----------

I think I have figured it out..

Code:
function CMLT_Report_2 {
pattern=$1
script=$2
procedure=$3
folder=$4
frequency=$5
# for file in $pattern
# do
#    check_filesize $file
#    CMLT_Report "$script" $file "$procedure" "/dbfs_direct/FS1/cmlrpt/" "$folder" "$frequency"
#    sh /dbfs_direct/FS1/MIE/script/CAMELOT_REPORTING_LOG.sql $script $report $procedure $file_dir $file_size $recnum $created $remarks $frequency
# done
while read file
do
  case $file in
    ($pattern) [ -f "$file" ] && check_filesize $file \
                              && CMLT_Report "$script" $file "$procedure" "/dbfs_direct/FS1/cmlrpt/" "$folder" "$frequency" \
                              && sh /dbfs_direct/FS1/MIE/script/CAMELOT_REPORTING_LOG.sql $script $report $procedure $file_dir $file_size $recnum $created $remarks $frequency
  esac
done < report_list.txt
}

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Help needed to Spawn Shell on Python and Continue Execution

def gob(url): print "\n\t Running gobuster on target." params = " -e -s '307,200,204,301,302' -t 20 -u " + url + " >> /tmp/%s/gobuster.txt" % (ip) os.system("xterm -e bash -c "tail -f /tmp/%/gobuster.txt"") for i in bflist: dirbf = "gobuster -w " + i... (3 Replies)
Discussion started by: alvinoo
3 Replies

2. Shell Programming and Scripting

Search files in UNIX based on execution

Hi, I have a UNIX script to fetch all the files for current day. so I am using code-- "files=($(find x.lst -maxdepth 1 -type f -daystart -mtime -1))". But this is not going to work if my job starts at 11 PM and continues till 1AM. In tht case I will loose all files between 11PM to 12AM. Is there... (3 Replies)
Discussion started by: usrrenny
3 Replies

3. Shell Programming and Scripting

how to continue shell script execution process without control going to pompt?

Hi Friends, Iam invoking another shell script to create B2k_session_id from my shell script.It is properly creating B2k_session_id and after creation control is coming out from the script and going to command prompt.The lines which are after the exectrusteduser.com sh.com are not executing..may... (5 Replies)
Discussion started by: vadlamudy
5 Replies

4. UNIX for Dummies Questions & Answers

Creating a column based list from a string list

I have a string containing fields separated by space Example set sr="Fred Ted Joe Peter Paul Jean Chris Tim Tex" and want to display it in a column format, for example to a maximum of a window of 100 characters And hopefully display some thing like Fred Ted Joe ... (3 Replies)
Discussion started by: kristinu
3 Replies

5. Emergency UNIX and Linux Support

invoke one script based on previous script execution

I am database guy and not very good at shell scripts. I am seeking help to sharp my script coding. I have 5 scripts 1. master script. I use this one to call other four scripts to do database work. 2. db_backup_1 and log_backup_1 3. db_backup_2 and log_backup_2 in master script, I want to... (4 Replies)
Discussion started by: duke0001
4 Replies

6. Shell Programming and Scripting

Execution problem with sort the file based on contents

My input file: >ali ASSDDGHFHFHJFJHJDSDGSDGSDGSDGSDGSDGSDGDSGDSGSDGDSGSDGSDGDSGSDGGDSG >zzz ASdASDASDSADSADDSADJKHJDSADKLJADKLSAJDLJLKJLDASDDSADd >abu ASDASDFSAFASFSADFASDASDSADSADSADSADSADSADASDASdSADSADSADA >aaa... (2 Replies)
Discussion started by: patrick87
2 Replies

7. Shell Programming and Scripting

Automatically Rerun a script based on previous execution output

Hi Experts, I have a shell script called "updatevs" that is scheduled to run at 6.00 am everyday via cronjob. The cronjob will execute this script and output to a log file. The functionality of this script is to read the database and run a set of commands. This script is generally successful... (6 Replies)
Discussion started by: forumthreads
6 Replies

8. UNIX for Dummies Questions & Answers

UNIX command to skip any warning messages and continue job execution

Hello All, Good day! This is my first UNIX post. :D Anyways, I would like to seek help from you guys if you know of any UNIX command that will skip a warning message once it is encountered but continue to run the execution. Ok here's the situation in general: An encypted file is sent to... (2 Replies)
Discussion started by: jennah_rekka
2 Replies

9. Shell Programming and Scripting

perl - understand process status and continue the code execution

Hello, I need advice on how to check if started processes are finished in perl, here's explanation : OS is RHEL 4, perl -v = "This is perl, v5.8.0 built for i386-linux-thread-multi" The logic of the script : #!/usr/bin/perl use warnings; $param1 = $ARGV; $param2 = $ARGV; $param3 =... (2 Replies)
Discussion started by: sysgate
2 Replies

10. UNIX for Advanced & Expert Users

file extension based software execution

Hi Experts, I am working in HP-UX 11.0 workstaion. How can i make a file to be executed with the corresponding software to be invoked or executed. as in Windows. ie., if a file index.html has to be double clicked to invoke the Netscape Navigator. What i have to do to achieve this... (2 Replies)
Discussion started by: anent
2 Replies
Login or Register to Ask a Question