Read a control file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read a control file
# 1  
Old 04-07-2014
Read a control file

Hi I have the below .sh script which receives a argument ftpClient=$1 . This argument i am trying to read from a control file called ftpProperties.control.
Based on the argument input(client_ftx OR client_ptm),the script shall read the particular entries from the control file like ftp host,user,pwd and connect.
I have a solaris box where i use bash. The awk command is failing (error attached).This script works fine in Linux but fails when i run from solaris.
Any help is appreciated.

(1)Script
******
Code:
#!/bin/ksh

YESTERDAY=`TZ=GMT+29 date +%Y%m%d`
ftpClient=$1
ftpPropertyFile=/app/temp/ftpProperties.control
cat $ftpPropertyFile|sed -n "/$ftpClient/,/<<EOF/p"|awk -v 'RS=\n\n' '1;{exit}'|tail -n +2 > $ftpClient.txt
. ./$ftpClient.txt
echo "start of script"
ftp -nv $HOST <<END_SCRIPT
user $USER $PASSWORD
cd $SOURCEPATH
lcd /data/file
get $FILENAME1$YESTERDAY
bye
END_SCRIPT

echo "end of script"

(2)Control File
************
Code:
[client_ftx]
HOST=ftpprod.com
USER=sam
PASSWORD=abc123
SOURCEPATH=/samdir
FILENAME1="stor_cax."


[client_ptm]
HOST=ids.com 
USER=ftpuser
PASSWORD=xyz234
SOURCEPATH=/ftpdir
FILENAME1="previousday.srv"

(3)Error
*******
Code:
usage: tail [+/-[n][lbc][f]] [file]
       tail [+/-[n][l][r|f]] [file]
start of script
Not connected.
Not connected.
awk: syntax error near line 1
awk: bailing out near line 1
Local directory now /data/file
Not connected.
end of script


Last edited by samrat dutta; 04-07-2014 at 02:29 PM..
# 2  
Old 04-07-2014
Try :

Code:
$ cat testfile
[client_ftx]
HOST=ftpprod.com
USER=sam
PASSWORD=abc123
SOURCEPATH=/samdir
FILENAME1="stor_cax."


[client_ptm]
HOST=ids.com 
USER=ftpuser
PASSWORD=xyz234
SOURCEPATH=/ftpdir
FILENAME1="previousday.srv"

Code:
$ cat tester
#!/bin/bash


control_file="testfile"

while read line
do

	[[ "$line" =~ ^HOST ]] && HOST="${line#*=}"
        [[ "$line" =~ ^USER ]] && USER="${line#*=}"
        [[ "$line" =~ ^PASSWORD ]] && PASSWORD="${line#*=}"
        [[ "$line" =~ ^SOURCEPATH ]] && SOURCEPATH="${line#*=}"

 if  [[ "$line" =~ ^FILENAME1 ]]; then

	FILENAME1="${line#*=}"
       

       # So now username password etc are parsed from control file 
       # Process whatever you want here...
  
       echo $HOST $USER $PASSWORD $SOURCEPATH $FILENAME1

 fi
 
done < "$control_file"

Code:
$ bash tester
ftpprod.com sam abc123 /samdir "stor_cax."
ids.com ftpuser xyz234 /ftpdir "previousday.srv"

# 3  
Old 04-07-2014
Hi I ran the below script. It basically reads the entire control file and displays. However My requirement is to pass into the main script an argument like client_ftx or client_ptm and the script should refer the ftpProperties.control file and read the relevant section details like ftp host,user,pwd. The script then shall connect to the respective FTP server based on this.

Code:
#!/bin/bash
control_file=/app/temp/ftpProperties.control
while read line
do

        [[ "$line" =~ ^HOST ]] && HOST="${line#*=}"
        [[ "$line" =~ ^USER ]] && USER="${line#*=}"
        [[ "$line" =~ ^PASSWORD ]] && PASSWORD="${line#*=}"
        [[ "$line" =~ ^SOURCEPATH ]] && SOURCEPATH="${line#*=}"

 if  [[ "$line" =~ ^FILENAME1 ]]; then

        FILENAME1="${line#*=}"


       # So now username password etc are parsed from control file
       # Process whatever you want here...

       echo $HOST $USER $PASSWORD $SOURCEPATH $FILENAME1

 fi

done < "$control_file"

# 4  
Old 04-07-2014
Fine, use this code

Code:
#!/bin/bash

# Use your $1 arguments here
client="client_ftx"

# Your FTP Control file
control_file="controlfile"

while read line
do

        [[ "$line" =~ ^\[    ]] && CLIENT="${line//[\[\]]/}"

	[[ "$line" =~ ^HOST  ]] && HOST="${line#*=}"
        [[ "$line" =~ ^USER  ]] && USER="${line#*=}"
        [[ "$line" =~ ^PASSWORD ]] && PASSWORD="${line#*=}"
        [[ "$line" =~ ^SOURCEPATH ]] && SOURCEPATH="${line#*=}"

 if [[ "$CLIENT" == "$client" ]] && [[ "$line" =~ ^FILENAME1 ]]; then

	FILENAME1="${line#*=}"
       

       # So now username password etc are parsed from control file 
       # Process whatever you want here...
  
       echo $CLIENT $HOST $USER $PASSWORD $SOURCEPATH $FILENAME1

 fi
 
done < "$control_file"

Code:
$ bash tester
client_ftx ftpprod.com sam abc123 /samdir "stor_cax."

I am not happy, after giving hints to parse file, you did not try anything to meet your requirement.
This User Gave Thanks to Akshay Hegde For This Post:
# 5  
Old 04-07-2014
You seem to already have the rest. Plug in your ftp -nv $HOST <<END_SCRIPT where needed.
# 6  
Old 04-07-2014
Thanks Friends.

Meanwhile in my original post i wanted to highlight the issue i faced using awk and tail in solaris . Can you guys help me to point out if anything is missed here ? Error is attached as well

Code:
#!/bin/bash
control_file=client_ptm
ftpPropertyFile=/app/temp/ftpProperties.control
cat $ftpPropertyFile|sed -n "/$control_file/,/<<EOF/p" |awk -v 'RS=\n' '1;{exit}'|tail -n +1 > $ftpClient.txt
. ./$ftpClient.txt

ERRROR:
******
Code:
usage: tail [+/-[n][lbc][f]] [file]
       tail [+/-[n][l][r|f]] [file]
start of script
Not connected.
Not connected.
awk: syntax error near line 1
awk: bailing out near line 1
Local directory now /data/file
Not connected.
end of script

# 7  
Old 04-09-2014
Quote:
Originally Posted by samrat dutta
Thanks Friends.

Meanwhile in my original post i wanted to highlight the issue i faced using awk and tail in solaris . Can you guys help me to point out if anything is missed here ? Error is attached as well
...
...
change awk to /usr/xpg4/bin/awk, /usr/xpg6/bin/awk , or nawk
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Creating script to read many files and load into database via single control file

Hi, I have many files but with only 2 names , I want to load the data of that file into database through sqlldr with single control file. how can i do that ????? Example: switch_file switch_file billing_file billing_file now these files should be loaded into same database but different... (1 Reply)
Discussion started by: niti_sharma
1 Replies

2. Shell Programming and Scripting

Read from file and execute the read command

Hi, I am facing issues with the below: I have a lookup file say lookup.lkp.This lookup.lkp file contains strings delimited by comma(,). Now i want to read this command from file and execute it. So my code below is : Contents in the lookup.lkp file is : c_e,m,a,`cd $BOX | ls cef_*|tail... (7 Replies)
Discussion started by: vital_parsley
7 Replies

3. Shell Programming and Scripting

Check whether file is processed in a control file list

I've a list of files which got processed in Target table A and stored in a control file(list of control files). I've want to trigger another process (later) based on this list of files and load into Target table B and continue running this process until this file list is exhuasted. How do I come... (1 Reply)
Discussion started by: manojg9
1 Replies

4. Shell Programming and Scripting

Formatting file data to another file (control character related)

I have to write a program to read data from files and then format into another file. However, I face a strange problem related to control character that I can't understand and solve. The source file is compose of many lines with such format: T_NAME|P_NAME|P_CODE|DOCUMENT_PATH|REG_DATE ... (3 Replies)
Discussion started by: hk6279
3 Replies

5. Shell Programming and Scripting

while "read" UNIDATA control character

I have a UNIDATA file with this line EIR.ENTRYýIND.RATE.CALCýBUILD.EIR.ITEMýIND.RATES.WEBSERVICEýIND.GRP.COMPLIANCEýIND.RATE.AUDIT If I edit my unidata file with Notepad++ or something and replace ý with ~ then this works IFS="~" while read DATA do My question is what do I need... (14 Replies)
Discussion started by: hpodhrad
14 Replies

6. UNIX for Dummies Questions & Answers

When reading a csv file, counter to read 20 lines and wait for minute then read next 20 till end

Hello All, i am a newbie and need some help when reading a csv file in a bourne shell script. I want to read 10 lines, then wait for a minute and then do a reading of another 10 lines and so on in the same way. I want to do this till the end of file. Any inputs are appreciated ... (3 Replies)
Discussion started by: victor.s
3 Replies

7. Shell Programming and Scripting

Control file

if TERM has the value vt220, where will you expect to find its control file (0 Replies)
Discussion started by: thelakbe
0 Replies

8. Programming

Cannot read a file with read(fd, buffer, buffersize) function

# include <stdio.h> # include <fcntl.h> # include <stdlib.h> # include <sys/stat.h> int main(int argc, char *argv) { int fRead, fPadded, padVal; int btRead; int BUFFSIZE = 512; char buff; if (argc != 4) { printf ("Please provide all of the... (3 Replies)
Discussion started by: naranja18she
3 Replies

9. Shell Programming and Scripting

Checking for a control file before processing a data file

Hi All, I am very new to Shell scripting... I got a requirement. I will have few text files(data files) in a particular directory. they will be with .txt extension. With same name, but with a different extension control files also will be there. For example, Sample_20081001.txt is the data... (4 Replies)
Discussion started by: purna.cherukuri
4 Replies
Login or Register to Ask a Question