Sponsored Content
Top Forums UNIX for Advanced & Expert Users Help with UNIX "File Open" Error Post 302919646 by Aia on Thursday 2nd of October 2014 06:48:49 PM
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:
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
CREAT(P)						     POSIX Programmer's Manual							  CREAT(P)

NAME
creat - create a new file or rewrite an existing one SYNOPSIS
#include <sys/stat.h> #include <fcntl.h> int creat(const char *path, mode_t mode); DESCRIPTION
The function call: creat(path, mode) shall be equivalent to: open(path, O_WRONLY|O_CREAT|O_TRUNC, mode) RETURN VALUE
Refer to open() . ERRORS
Refer to open() . The following sections are informative. EXAMPLES
Creating a File The following example creates the file /tmp/file with read and write permissions for the file owner and read permission for group and oth- ers. The resulting file descriptor is assigned to the fd variable. #include <fcntl.h> ... int fd; mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; char *filename = "/tmp/file"; ... fd = creat(filename, mode); ... APPLICATION USAGE
None. RATIONALE
The creat() function is redundant. Its services are also provided by the open() function. It has been included primarily for historical purposes since many existing applications depend on it. It is best considered a part of the C binding rather than a function that should be provided in other languages. FUTURE DIRECTIONS
None. SEE ALSO
open() , the Base Definitions volume of IEEE Std 1003.1-2001, <fcntl.h>, <sys/stat.h>, <sys/types.h> COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technol- ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html . IEEE
/The Open Group 2003 CREAT(P)
All times are GMT -4. The time now is 04:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy