Compare data with while if else loop ?!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare data with while if else loop ?!
# 1  
Old 02-20-2018
Code Compare data with while if else loop ?!

Good midday and hello to everyone! =)

If I describe some things wrong please be aware, that english is not my native language!! Smilie

I'm a bit stuck with a script I need to finish. Due to data protection I need to hide some paths but that should be no problem.

My script connects to a db2 database and pulls the information of "app_name" and "app_version". It then compares the two parameters with a directory. If some of the names and versions do not match or can't be found it needs to check if the untraceable data can be found in another file. The format I pull out of the database is like this: AAL;00.01-02; first the "app_name" and second the "app_version"

This is the part where I am stuck. Maybe i'm just to tired or I think way to complicated but I can't find a solution Smilie


Code:
function readdatabase() {
test -f /opt/XXXX/tc/conf/TC.conninfo || ftc_die "Datei nicht gefunden --> Abbruch"
  ftc_info "TC.conninfo einlesen"
  . /opt/XXXX/tc/conf/TC.conninfo && ftc_ok "Datei vorhanden --> Einlesen"
  ftc_info "Verbinde mit DB2 Datenbank"
  db2 connect to $CONN_DB user $CONN_USER using $CONN_PW || ftc_die "DB-Connect fehlgeschlagen"
  ftc_ok "DB-Connect erfolgreich"
  ftc_info "Hole app_name und app_version aus DB"
  db2 -x "select distinct trim(lower(app_name_ga)) || ';' || trim(app_version_ga) from tanc_gavR4" | \
  #sed -e 's|/modules_|;|;s|.properties||' > $FTC_TMPDIR/tanc_gav.tmp
  sed -e " /^$/ d" \
  > $FTC_TMPDIR/tanc_gav.tmp
  cd /opt/tomcat_xxx_1/webapps/xxx/app && \
  ls -d */modules_* | \
  sed -e 's|/modules_|;|;s|.properties||' > $FTC_TMPDIR/directory.tmp
  while read -r ZEILE ; do
     APP=${ZEILE/;*}
     VER=${ZEILE/*;}
     test -f /opt/tomcat_xxx_1/webapps/xxx/app/$APP/modules_$VER.properties || ftc_warning "$APP;$VER fehlt"
#   cat /var/servershare/scripts/templates/webanwendungen.dbin | sed -e 's|/modules_|;|;s|.properties||'
  done < $FTC_TMPDIR/tanc_gav.tmp
}

So my idea was to use a while if else statement and compare the modules that can't be find with the "webanwendungen.dbin" but I don't know how to do that.

If you need further information please let me know.

Thank you in advance!

Last edited by dsondermann; 02-20-2018 at 08:28 AM.. Reason: Missing brace
# 2  
Old 02-20-2018
Welcome to the forum.

Having read your verbal description thrice I'm not sure I understood your problem, and your function listing doesn't really help. Input / file data and / or directory structures / contents would have been beneficial, as would have some decent indentation of the code. Line continuation hitting comment lines won't work, I'm afraid.

Let me paraphrase what I found after having removed all the logging / messaging fuss:
Define the three "authentication variables" by sourcing file TC.conninfo.
Connect to DB.
Select app_name;app_version from DB, modify with some sed script into a temp file.
Create some other temp file from a certain, sed modified, directory listing never to be used.
Read and test first temp file's contents against some directory contents, print warning msg if missing.

What exactly doesn't work (the way you expect)? Post input data to analyse / work upon.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Compare data - Match first column and compare second

Hi guys, looking for some help with a way to compare data in two files but with some conditions. example, File 1 consists of site1,10.1.1.1 site2,20.2.2.2 site3,30.3.3.3 File 2 contains site1,l0.1.1.1 site2,50.1.1.1 site3,30.3.3.3 site4,40.1.1.1 I want to be able to match the... (1 Reply)
Discussion started by: mutley2202
1 Replies

2. Shell Programming and Scripting

Unable to compare to a previous value of a variable in a while loop for a file

Hello All, I'm working on a script that will actually read a file consisting of data like the below:(ReportID,Sub_reportID,Sub_reportName) 1,1,ABC 1,2,DEF 1,3,GHI 2,1,JKL 2,2,MNO 3,1,PQR I want to read the Sub Report details for a Report_ID using while loop and write these values into... (6 Replies)
Discussion started by: venkat_reddy
6 Replies

3. Shell Programming and Scripting

Shell do loop to compare two columns (duplicates)

Hello, I have a single text file with three columns like: 2 1 10 3 6 11 4 4 12 5 5 13 6 8 14 I was wondering how I can run a shell script to (do loop) to read the first point in the first column , compare it with all the points in the second column and if they are the same,... (12 Replies)
Discussion started by: Paul Moghadam
12 Replies

4. Shell Programming and Scripting

Compare 2 files and match column data and align data from 3 column

Hello experts, Please help me in achieving this in an easier way possible. I have 2 csv files with following data: File1 08/23/2012 12:35:47,JOB_5330 08/23/2012 12:35:47,JOB_5330 08/23/2012 12:36:09,JOB_5340 08/23/2012 12:36:14,JOB_5340 08/23/2012 12:36:22,JOB_5350 08/23/2012... (5 Replies)
Discussion started by: asnandhakumar
5 Replies

5. Shell Programming and Scripting

Re: Read lines and compare in a loop

I have a file which has following content: NAME=ora.DG1.dg TYPE=ora.diskgroup.type TARGET=ONLINE STATE=ONLINE NAME=ora.DG2.dg TYPE=ora.diskgroup.type TARGET=ONLINE STATE=ONLINE NAME=ora.DG3.dg TYPE=ora.diskgroup.type TARGET=ONLINE STATE=ONLINE NAME=ora.DG4.dg... (7 Replies)
Discussion started by: rcc50886
7 Replies

6. Shell Programming and Scripting

need help to compare 2 files inside a loop

Basically, I have a user input a colour into a variable, and then i echo that variable into a text file. Then I need to compare those 2 files which is easy using the diff command. The thing I can not get is how to do this inside of a loop until the variable matches the file. Also if the user enters... (6 Replies)
Discussion started by: cstadnyk1
6 Replies

7. Shell Programming and Scripting

[Solved] Endless while loop when compare files

Hi All, I've written a script to read 2 files and compare the contents using while loop but somehow when $line is not found in test2, the script will continue looping. Below is my code, pls advise what could went wrong TIA Nick for line in test1.txt | while read line do grep -i... (4 Replies)
Discussion started by: Nick1971
4 Replies

8. Shell Programming and Scripting

Get data from 3 differrnt oracle DB & then compare data

Hi All, I have a requirement to write a shell script for the following... we have 3 different database.... lets say A, B, C From these 3 DBs, i need to get data.. all have 3 different table...a,b, c A.a => Emp_code, count(*) B.b => emp_code, count(*) C.c => emp_code, copunt(*) Once get this... (4 Replies)
Discussion started by: Amit.Sagpariya
4 Replies

9. Shell Programming and Scripting

Using loop reading a file,retrieving data from data base.

Hi All, I am having trouble through, I am reading the input from tab delimited file containing several records, e.g. line1 field1 field2 field3 so on.. line2 field1 field2 field3 so on.. .. .. on the basis of certain fields for each record in input file, I have to retrieve... (1 Reply)
Discussion started by: Sonu4lov
1 Replies

10. UNIX for Dummies Questions & Answers

compare data

Hi, my problem is, I have to files, one is a log file of an actual execution, the other file is a pattern file. The entries "abcd,,!!11.22!!,3asdf" and "abcd,,!!xx.xx!!,3asdf" should be identified as equal. At the position of the x in the pattern file, the log file must have... (3 Replies)
Discussion started by: bensky
3 Replies
Login or Register to Ask a Question