Issues using array credentials to read contents of a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issues using array credentials to read contents of a file
# 1  
Old 05-12-2011
Data Issues using array credentials to read contents of a file

Hi,

I am trying to read the contents of a file using array credentials in unix. The file I am trying to read is tab separated and contains the below contents.

# partnerid Direc Server Port Source_Dir Target_Dir Mask Remove Files Passwordless Compare Files CopyLatest

I am reading the lines using a while loop and setting values using below command.
set -A CREDENTIALS_ARRAY ${line}

The first time I run the script it sets all the 11 parameters correctly in the array and script executes fine.Basically I read the contents to transfer the file $Mask from source to destination. Have shown sample files below. Mask has been set to achan* When I execute the script the second time it sets Mask=achan_dwh.sas7bdat and Remove Files=achan_dwh.sas7bndx , hence shifting the values forward by 1 parameter thereby setting the value of Remove Files into Passwordless field. Actually remove file is set to "N" and passwordless to "Y" but in this case sets passwordless to "N" and goes into the other section of the code to validate the Identity key which is wrong.

-rwxr-x--- 1 transfer sassrvOP 24576 May 12 19:26 achan_dwh.sas7bdat
-rwxr-x--- 1 transfer sassrvOP 24576 May 12 19:26 achan_dwh.sas7bndx

I suspect the array credentails is not getting cleared in the second run. IS there a way I could reset the array to zero each run or do you suspect some other issue here? Have not put the code since it is really huge.

It would be great if you could help me on this. Thanks in advance.
# 2  
Old 05-13-2011
I wonder if it's taking -rwxr-x--- to be a parameter. My ksh certainly does, and tells me it's a malformed one, but who knows what that might mean on some other implementation. Try putting a -- between -A whatever and ${line} to tell it that anything following is a parameter and not a flag.

set -A arrayname -- ${line}
# 3  
Old 05-13-2011
Hi,

Tried that but doesnt work. Is there a limit on the parameters an array can read? The script worked fine with 9 parameters, now I have included another two and its causing issues.

Contents of the file I am trying to read. Last two columns have been added.
# partnerid Direc Server Port Source_Dir Target_Dir Mask Remove Files Passwordless Compare Files CopyLatest
xyz I abc nn /ddd/eee/fff aaa/TEST uchan* N Y Y N
xyz I abc nn /ddd/eee/fff aaa/TEST achan_dwh* N Y Y N

It reads the first line correctly by the second line is read incorrectly.

From the logs:
1st line:
+ set -A CREDENTIALS_ARRAY xyz I abc nn /ddd/eee/fff aaa/TEST uchan* N Y Y N

2nd line: This is an issue. Instead of reading achan_dwh* it reads the actual file mask from the destination.

set -A CREDENTIALS_ARRAY sassrvF xyz I abc nn /ddd/eee/fff aaa/TEST achan_dwh.sas7bdat achan_dwh.sas7bndx N Y N N
# 4  
Old 05-13-2011
Maybe if you posted your actual code.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Place the contents of a .CSV file to an array

Hi, I am trying to place the contents of a .CSV file to an array, but not sure how to do that. Here is my .CSV file content: App,SLA,Job name,Avg start time,Avg run time,Frequency,Downstream apps XYZ,,ABC14345,3:00 AM,00.04.00,Daily,STAMP XYZ,9:00,ABC12345,3:15 AM,00.05.00,Daily,STAMP ... (4 Replies)
Discussion started by: ajayakunuri
4 Replies

2. Shell Programming and Scripting

Replace partial contents of file with contents read from other file

Hi, I am facing issue while reading data from a file in UNIX. my requirement is to compare two files and for the text pattern matching in the 1st file, replace the contents in second file by the contents of first file from start to the end and write the contents to thrid file. i am able to... (2 Replies)
Discussion started by: seeki
2 Replies

3. Programming

read() contents from a file

Hi, I'm trying to implement a C program on ubuntu which reads the contents of a file that is passed in as an argument and then displays it to the screen. So far I've cobbled together this from bits online but most of it is probably wrong as its all copied and pasted... #include <stdio.h>... (2 Replies)
Discussion started by: cylus99
2 Replies

4. Shell Programming and Scripting

Write array contents to file

Hi, I have a bash script that currently holds some data. I am trying to write all the contents to a file called temp.txt. I am using echo ${array} > temp.txt The problem that I am experiencing is that the elements are being written horizontally in the file. I want them written... (5 Replies)
Discussion started by: Filter500
5 Replies

5. Shell Programming and Scripting

how to read contents of file?

I have made a script something like this. I want it to read the contents of either file or directory but 'cat' and 'ls' is not working. Can anyone help me? I am a newbie in scripting so dont know much about it. I also dont know how can i put my code separatly on this forum #!/bin/bash echo... (9 Replies)
Discussion started by: nishrestha
9 Replies

6. Homework & Coursework Questions

How to read contents of a file into variable :(

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have to read the contents of each field of a file creating user accounts. The file will be of format : ... (6 Replies)
Discussion started by: dude_me5
6 Replies

7. Shell Programming and Scripting

Read contents from a file

Hi Friends, I am new to this forum. Just struck up with a logic. I have a csv file seperated by ":" (colons). This csv file contains hostname and groups as follows: HOSTNAME:VT Group SGSGCT2AVPX001:Team1 SGSGCT2AVPX003:Team2 SGSGCT2AVPX005:Team2 PHMNCTTAVPX001:Team3 I want to... (2 Replies)
Discussion started by: dbashyam
2 Replies

8. Shell Programming and Scripting

Most reliable way to store file contents in an array in bash

Hi Guys, I have a file which has numbers in it separated by newlines as follows: 1.113 1.456 0.556 0.021 -0.541 -0.444 I am using the following code to store these in an array in bash: FILE14=data.txt ARRAY14=(`awk '{print}' $FILE14`) (6 Replies)
Discussion started by: npatwardhan
6 Replies

9. UNIX for Dummies Questions & Answers

compare array contents with file

I have an array "arrA" with the following contents: A0012 Paint Shop.doc ES001 Contract Signature.doc Budget Plan.pdf TS PWS.pdf My data file "Files.dat" has the same contents: A0012 Paint Shop.doc ES001 Contract Signature.doc Budget Plan.pdf TS PWS.pdf I have a script that compares... (0 Replies)
Discussion started by: orahi001
0 Replies

10. Shell Programming and Scripting

Can I assign the contents of file into an array?

I am trying to assign the contents of file e.g ls "$HOME" into an array. If it is possible then please guide me without using the concept of awk,sed, and perl16 Thanks (10 Replies)
Discussion started by: murtaza
10 Replies
Login or Register to Ask a Question