Help with UNIX "File Open" Error


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Help with UNIX "File Open" Error
# 1  
Old 10-02-2014
Help with UNIX "File Open" Error

We have a script that runs and picks up some files to later be used in Oracle. Every now and again we get a ERROR 'filename' file is open We know for a fact the files are not open. The files are created early morning and not used until the next morning by the script. If we manually open the file then close it, the script will pick it up with no errors.


Anyone run into this issue? I am willing to post the script if need be.

Thanks,
Randy

Last edited by rbatte1; 10-03-2014 at 12:47 PM.. Reason: Changed font/colour formatting to ICODE tags
# 2  
Old 10-02-2014
How does this script determine if a file is open?
This User Gave Thanks to achenle For This Post:
# 3  
Old 10-02-2014
We are using:
Code:
 
if [ `fuser $i 2>&1 | awk '{ printf "%s",$2 }' | wc -c` -eq 0 ]
     then
       #FILE IS CLOSED
       echo "--------------------------------------------------------------------"

# 4  
Old 10-02-2014
Quote:
Originally Posted by randybrazil
We are using:
Code:
 
if [ `fuser $i 2>&1 | awk '{ printf "%s",$2 }' | wc -c` -eq 0 ]
     then
       #FILE IS CLOSED
       echo "--------------------------------------------------------------------"

You are redirecting errors to stdout. Is there ever the possibility that fuser errors and pass the bytes alone all the way to wc, evaluating to the equivalent of "FILE IS OPEN"? YES.

Allow me to show you the concept:
Code:
% ls do_not_exist
ls: cannot access do_not_exist: No such file or directory

% ls do_not_exist | wc -c
ls: cannot access do_not_exist: No such file or directory
0

% ls do_not_exist 2>&1 | wc -c
58

% ls do_not_exist 2>&1 | awk '{printf "%s", $2}' |  wc -c
6

These 2 Users Gave Thanks to Aia For This Post:
# 5  
Old 10-02-2014
Quote:
Originally Posted by Aia
You are redirecting errors to stdout. Is there ever the possibility that fuser errors and pass the bytes alone all the way to wc, evaluating to the equivalent of "FILE IS OPEN"? YES.

Allow me to show you the concept:
Code:
% ls do_not_exist
ls: cannot access do_not_exist: No such file or directory

% ls do_not_exist | wc -c
ls: cannot access do_not_exist: No such file or directory
0

% ls do_not_exist 2>&1 | wc -c
58

% ls do_not_exist 2>&1 | awk '{printf "%s", $2}' |  wc -c
6

Nice catch.
This User Gave Thanks to achenle For This Post:
# 6  
Old 10-02-2014
Help with UNIX "File Open" Error

I am sorry, i shuold have posted the whole script. I am new to the forum. Thanks for all the insight and help so far. Here is the script.

sfdomain2 /u20/apps/arms/scripts (RM01) :cat process_auth.ksh
#!/bin/ksh
Code:
 
#################################################################
#
# File Name: process_auth.ksh
#
# Function: Calls load_auth.ksh for all located auth files
#
# $Revision: 1.3 $
#
#################################################################
JOB="process_auth"
USAGE="USAGE:  process_auth.ksh {YYYYMMDD} {BANK MPS|NOVA}"
#execute .profile to get environment
. $HOME/.app_profile
fail_notify()
{
   cat $OUTF | mailx -s "FAIL: $JOB " `cat $APP_BASE/secured/failDB.mail`
   cat $OUTF > $APP_BASE/trigger/$JOB.error
   exit 1
}
#PHJ - CO 3094: failDB.mail includes Madhu and Sharma Pandyaram in the failure notification list.
if [ $# != 2 ]
then
  echo $USAGE
else
BANK=$2
cdate=$1
OUTF=$APP_BASE/log/$JOB.$BANK.log.`date '+%Y%m%d%H%M'`

#begin log block
{
if ls $APP_BASE/trigger | grep error > /dev/null
then 
  echo ">>>   Error trigger file exists"
  fail_notify;
fi
echo "`date +'%m-%d-%Y %H:%M:%S'` truncating S_AUTH table" 
sqlplus -S / << EOF
truncate table app_stratus.s_auth reuse storage;
--delete from app_stratus.s_auth;
--commit;
EOF
#build list of authorization files for parameter date
cd $IRM_INCOMING/auth
########## NOVA BANK FILE PROCESSING ##############
if [ $BANK = "NOVA" ] 
then
for i in `ls *${cdate}*`
do
# call load script with date and filename to process
  if echo $i | grep usb > /dev/null
  then
   echo "BYPASSING USB AUTH FILES - USBANK FILE, NOT NOVA"
  else
    if echo $i | grep stratus > /dev/null
    then
     echo "BYPASSING STRATUS TRANSFER LOG FILES"
    else
     if [ `fuser $i 2>&1 | awk '{ printf "%s",$2 }' | wc -c` -eq 0 ]
     then
       #FILE IS CLOSED
       echo "--------------------------------------------------------------------"
       # record attributes; dup check
       echo "`date +'%m-%d-%Y %H:%M:%S'` recording file attributes $i"
       FILEATTR=`$IRM_HOME/scripts/record_file_attr_new.ksh $IRM_INCOMING/auth $i  grep RESULT | cut -f2 -d"|"`
       if [ $? -eq 0 ] 
       then
         echo "`date +'%m-%d-%Y %H:%M:%S'` CALL load_auth.ksh $1 $i"
         cp  $IRM_INCOMING/auth/$i  $IRM_INCOMING/auth/s_auth.dat
         chmod a+r $IRM_INCOMING/auth/s_auth.dat
         sqlplus -S / << EOF
exec app_stratus.pkg_load_stratus.load_auth(to_date('$1','YYYYMMDD'),'${i}');
EOF

#         $IRM_HOME/scripts/load_auth.ksh $1 $i
         echo "`date +'%m-%d-%Y %H:%M:%S'` MOVE $i to archive directory"
         mv $IRM_INCOMING/auth/$i $IRM_ARCHIVE/auth/$i
       else
         echo "`date +'%m-%d-%Y %H:%M:%S'` $i possible duplicate file, marking as duplicate; bypassing load"
         mv $i $i.duplicate
         compress $i.duplicate
         mv $i.duplicate.Z $IRM_ARCHIVE/auth
       fi   #FILEATTR=0
     else
       #log error because file is open
       banner "* ERROR *"
       echo "`date +'%m-%d-%Y %H:%M:%S'` ERROR $i file is open"
       fail_notify;
     fi  #is file open
   fi #STRATUS_TRANSFER_LOG
 fi #USBfilename
 
done
fi #BANK

########## USB/MPS BANK FILE PROCESSING ##############
#
# get all USB files regardless of date string within filename
# parameter filedate is used for settlement date
#
if [ $BANK = "MPS" ] 
then
for i in `ls usb*`
do
  
     if [ `fuser $i 2>&1 | awk '{ printf "%s",$2 }' | wc -c` -eq 0 ]
     then
       #FILE IS CLOSED
       echo "--------------------------------------------------------------------"
       # record attributes; dup check
       echo "`date +'%m-%d-%Y %H:%M:%S'` recording file attributes $i"
       FILEATTR=`$IRM_HOME/scripts/record_file_attr_new.ksh $IRM_INCOMING/auth $i | grep RESULT | awk '{ print $2 }'`
       if [ $? -eq 0 ] 
       then
         echo "`date +'%m-%d-%Y %H:%M:%S'` CALL load_auth.ksh $1 $i"
#         $IRM_HOME/scripts/load_auth.ksh $1 $i
         echo "`date +'%m-%d-%Y %H:%M:%S'` MOVE $i to archive directory"
         cp  $IRM_INCOMING/auth/$i  $IRM_INCOMING/auth/s_auth.dat
         chmod a+r $IRM_INCOMING/auth/s_auth.dat
         sqlplus -S / << EOF
exec app_stratus.pkg_load_stratus.load_auth(to_date('$1','YYYYMMDD'),'${i}');
EOF
         
         
         
         mv $IRM_INCOMING/auth/$i $IRM_ARCHIVE/auth/$i
       else
         echo "`date +'%m-%d-%Y %H:%M:%S'` $i possible duplicate file, marking as duplicate; bypassing load"
         mv $i $i.duplicate
         compress $i.duplicate
         mv $i.duplicate.Z $IRM_ARCHIVE/auth
       fi   #FILEATTR=0
     else
       #log error because file is open
       banner "* ERROR *"
       echo "`date +'%m-%d-%Y %H:%M:%S'` ERROR $i file is open"
       fail_notify;
     fi
   
done
fi #BANK = MPS

# Do a call to app_stratus.pkg_load_stratus.auth(to_date('$1','YYYYMMDD'));
echo "`date +'%m-%d-%Y %H:%M:%S'` CALL PL/SQL: PKG_LOAD_STRATUS.LOAD_AUTH($1)" 
sqlplus -S / << EOF
exec app_stratus.pkg_load_stratus.auth(to_date('$1','YYYYMMDD'));
EOF
#Check return code for error
status=$?
echo "`date +'%m-%d-%Y %H:%M:%S'` submitting background file compression at archive site" 
} >> $OUTF
if [ $status -ne 0 ]
then
  fail_notify;
else
  echo $1 > $APP_BASE/trigger/$JOB.$BANK
fi  #STATUS
if [ $BANK = "MPS" ] 
then
compress $IRM_ARCHIVE/auth/usb*.4 &
else
compress $IRM_ARCHIVE/auth/*$1* &
fi
fi #usage
exit

# 7  
Old 10-02-2014
Posting the relevant portion of the pertaining code is always the most useful thing that your request can have, thus thank you for that.

Still, nothing posted afterwards have had the power to amend what I have previously mentioned to you.

This evaluation representing that a file is not open:
Code:
if [ `fuser $i 2>&1 | awk '{ printf "%s",$2 }' | wc -c` -eq 0 ]

has an else clause in case that the file is open:
Code:
else
       #log error because file is open
       banner "* ERROR *"
       echo "`date +'%m-%d-%Y %H:%M:%S'` ERROR $i file is open"
       fail_notify;

One issue is that under some circumstances that evaluation is misrepresented, if fuser errors, because, the error stream pollutes the stdout stream with unwanted information.

Let me put it in another words: you have a bug.
2>&1 should not be there in this case
You could use 2> /dev/null

Perhaps, it would be helpful if you can look into: why to avoid the use of `ls` in a for loop.

That's a link to information I found for you, concerning the "gotchas" of parsing the content of `ls` in a loop.
This User Gave Thanks to Aia For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Expect: spawn id exp5 not open while executing "expect "$" { send "sudo su -\r" }"

Hi All, i am trying to ssh to a remote machine and execute certain command to remote machine through script. i am able to ssh but after its getting hung at the promt and after pressing ctrl +d i am gettin the out put as expect: spawn id exp5 not open while executing "expect "$" {... (3 Replies)
Discussion started by: Siddharth shivh
3 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. UNIX for Dummies Questions & Answers

Unix "look" Command "File too large" Error Message

I am trying to find lines in a text file larger than 3 Gb that start with a given string. My command looks like this: $ look "string" "/home/patrick/filename.txt" However, this gives me the following message: "look: /home/patrick/filename.txt: File too large" So, I have two... (14 Replies)
Discussion started by: shishong
14 Replies

5. SCO

sco unix backward compatibility on "max open file per process"

Hi How to increase maximum number of open file in "sco xenix binary" running in "sco unix openserver 5.0.7" ? I have changed "NOFILES" kernel parameter to 512, but xenix binray can't open more than 60. tnx (4 Replies)
Discussion started by: javad1_maroofi
4 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Solaris

Solaris 10 - Unable to boot the system "panic: cannot open /kernel/amd64/unix"

Hi All, I have installed Solaris 10 on my AMD 64 3000+ system. I was playing with grub commands eeprom and bootadm commands. I screwed my boot-file and now am unable to boot the system. Gets error msg as "panic: cannot open /kernel/amd64/unix". I booted the system is filesafe and tried update the... (2 Replies)
Discussion started by: Manjunath K V
2 Replies

8. SuSE

VMDB Failure" followed by "Unable to open snapshot file"

keep getting an error when I try to revert to a snapshot: "VMDB Failure" followed by "Unable to open snapshot file" Im using vmware server 1.0.4, host OS is windows xp and guest OS is SLES. Is there anything I can do to recover the snapshot or am I in trouble!?!?! (0 Replies)
Discussion started by: s_linux
0 Replies

9. Solaris

A NEW version of "boot: cannot open kernel/sparcv9/unix "

Ok, I found this article: https://www.unix.com/sun-solaris/19665-boot-cannot-open-kernel-sparcv9-unix.html However it doesn't quite describe my situation. I have created a jumpstart DVD that works great, and installs my customized Solaris-10 (Yes 10, not 8 or 9 per previous posts) . It... (6 Replies)
Discussion started by: biea
6 Replies
Login or Register to Ask a Question