UNIX File handling -Issue in reading a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting UNIX File handling -Issue in reading a file
# 1  
Old 08-16-2010
Data UNIX File handling -Issue in reading a file

I have been doing automation of daily check activity for a server, i have been using sqls to retrive the data and while loop for reading the data from the file for several activities. BUT i got a show stopper the below one.. where the data is getting store in $temp_file, but not being read by while loop. can anyone help in this..wots wrong with this.

Code:
TEMP_FILE=store.tmp
sqlplus -s ${DB_USER}/${DB_PASS}@${DB} > $TEMP_FILE <<EOF
        set pages 0
        set line 120
        SET FEEDBACK OFF
        SELECT username,machine,count(*)as sessions FROM v\$session WHERE status='INACTIVE' GROUP BY username,machine;
        exit; #this is storing result perfectly in file $TEMP_FILE
  EOF
        {
         while read rec; do
         #if [ "${rec}" != "" ] ; then
        echo "line is :$rec"       # nothing is coming (reading)
        usern=`echo $rec|awk '{print $1;}'`
        mach=`echo $rec|awk '{print $2;}'`
        sesn=`echo $rec|awk '{print $3;}'`
        echo "$usern : $mach: $sesn" # nothing is coming
          #fi
        done } < $TEMP_FILE

#Running with set -x /set -v output is as follows
Code:
+ sqlplus -s user/pa55word@myDB
+ 1> store.tmp 0<<
        set pages 0
        set line 120
        SET FEEDBACK OFF
        SELECT username,machine,count(*)as sessions FROM v$session WHERE status='INACTIVE' GROUP BY username,machine;
        exit;
  EOF
        {
         while read rec; do
         #if [ "" != "" ] ; then
        echo "line is :"
        usern=+ awk {print $1;}
+ awk {print $1;}
+ echo
+ echo
 mach=+ awk {print $2;}
+ awk {print $2;}
+ echo
+ echo
        sesn=+ awk {print $3;}
+ awk {print $3;}
+ echo
+ echo

# 2  
Old 08-16-2010
It's this line:

Code:
  EOF

Should not have an indentation:

Code:
EOF


It's quite interesting that the "-s" (silent) switch to sqlplus has hidden the fact that half your script went into the sql program! The sql interpreter stopped looking when is saw "exit".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

File handling issue

Hi All, I am running into an issue. I have a very big file. Wants to split it in smaller chunks. This file has multiple header/ trailers. Also, between each header/trailer there are records. Number of records in each header trailer combination can vary. Also, headers can start with... (3 Replies)
Discussion started by: Gurkamal83
3 Replies

2. Shell Programming and Scripting

awk issue while reading from file in while do

Hi Friends, I am trying to scan line by line using awk and pull the values and pass it in variables and then will use the variables but doesn't work. Please see below for details. #more dbtest.sh ---------------------------------- #!/bin/bash . $HOME/.bash_profile while read line do... (6 Replies)
Discussion started by: narunice
6 Replies

3. UNIX for Dummies Questions & Answers

Large file data handling issue

I have a single record large file, semicolon ';' and pipe '|' separated. I am doing a vi on the file. It is throwing an error "File to long" I need to actually remove the last | symbol from this file. sed -e 's/\|*$//' filename is working fine for small files. But not working on this big... (13 Replies)
Discussion started by: Gurkamal83
13 Replies

4. Shell Programming and Scripting

UNIX file handling issue

I have a huge file semicolon( ; ) separated records are Pipe(|) delimited. e.g abc;def;ghi|jkl;mno;pqr|123;456;789 I need to replace the 50th field(semicolon separated) of each record with 9006. The 50th field can have no value e.g. ;; Can someone help me with the appropriate command. (3 Replies)
Discussion started by: Gurkamal83
3 Replies

5. Shell Programming and Scripting

Reading UNIX commands from file and redirecting output to a file

Hi All I have written the following script: #!/bin/ksh while read cmdline do echo `$cmdline` pid="$cmdline" done<commands.txt =========== commands.txt contains: ps -ef | grep abc | grep xyz |awk '{print $2}; My objective is to store the o/p of the command in a variable and do... (8 Replies)
Discussion started by: rahulparo
8 Replies

6. UNIX for Dummies Questions & Answers

File Handling in UNIX

Hi all, I have a requirement here where I am dealing with a dynamic file. Each record in the file can contain anywhere between 1(min) to 42(max) Reject codes. For example I may have one record in the file having 3 reject codes and another record having 5 reject codes. The reject codes will be... (2 Replies)
Discussion started by: sujainarayan
2 Replies

7. UNIX for Dummies Questions & Answers

issue on reading the file and appending date

Hi Am having issue on appending time stamp I know the exact file names in the directory like a.dat b.dat c.dat e.dat f.dat I want to read all these file names and append the timestamp to each files like a.dat.20090604,b.dat.20090604 and move to the different directory. ... (3 Replies)
Discussion started by: bobprabhu
3 Replies

8. UNIX for Advanced & Expert Users

Issue reading csv file

HI All I have csv file containing the data like this Electrical Equipment,ElecEquip "Engineering, Machinery & Equipment",Engineerin Entertainment & Broadcasting,Entertain The first and third record are fine,The issue with second records as it has comma enclosed with in inverted... (1 Reply)
Discussion started by: mohdtausifsh
1 Replies

9. Shell Programming and Scripting

File handling, getopts command in unix

I need to create a shell script having the menu with few options such as 1. Listing 2. Change permissions 3. Modify Contents 4. Delete Files 5. Exit 1. For 1. Listing: Display a special listing of files showing their date of modification and access time (side by side) along with their... (2 Replies)
Discussion started by: bab123
2 Replies

10. UNIX for Dummies Questions & Answers

File handling in UNIX

Hi All, I want to read a file in UNIX line by line. Can u suggest me any command for this? (4 Replies)
Discussion started by: VENC22
4 Replies
Login or Register to Ask a Question