Sponsored Content
Top Forums UNIX for Advanced & Expert Users Help with UNIX "File Open" Error Post 302919652 by Scrutinizer on Thursday 2nd of October 2014 07:44:58 PM
Old 10-02-2014
I think aka has a good point, but there is a slight complication to this, since according to the man page:

Quote:
The fuser utility shall write diagnostic messages to standard error.

The fuser utility also shall write the following to standard error:

The pathname of each named file is written followed immediately by a <colon>.

For each process ID written to standard output, the character 'c' shall be written to standard error if the process is using the file as its current directory and the character 'r' shall be written to standard error if the process is using the file as its root directory. Implementations may write other alphabetic characters to indicate other uses of files.
So when stderr is redirected to stdout (2>&1) the filename with a colon and a space is prepended to the process numbers and a newline is added at the end

If stderr is redirected to /dev/null (2>/dev/null) then the first PID is no longer in column 2 (also there is no longer a closing newline) , so then the awk part is no longer required (nor will it work properly), so instead one could try:

Code:
if [ $(fuser -- "$i" 2>/dev/null | wc -c) -eq 0 ]

or
Code:
if [ -z "$(fuser -- "$i" 2>/dev/null)" ]

-- is used here, so that file names that start with a - cannot break the command... ( The pattern used in the for loop for i in *${cdate}* would leave that possibility open, whereas with for i in usb* that would not be strictly necessary, but it wouldn't hurt either)

Last edited by Scrutinizer; 10-03-2014 at 01:12 AM..
 

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

NAME
fuser - list process IDs of all processes that have one or more files open SYNOPSIS
fuser [ -cfu ] file ... DESCRIPTION
The fuser utility shall write to standard output the process IDs of processes running on the local system that have one or more named files open. For block special devices, all processes using any file on that device are listed. The fuser utility shall write to standard error additional information about the named files indicating how the file is being used. Any output for processes running on remote systems that have a named file open is unspecified. A user may need appropriate privilege to invoke the fuser utility. OPTIONS
The fuser utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines. The following options shall be supported: -c The file is treated as a mount point and the utility shall report on any files open in the file system. -f The report shall be only for the named files. -u The user name, in parentheses, associated with each process ID written to standard output shall be written to standard error. OPERANDS
The following operand shall be supported: file A pathname on which the file or file system is to be reported. STDIN
Not used. INPUT FILES
The user database. ENVIRONMENT VARIABLES
The following environment variables shall affect the execution of fuser: LANG Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of IEEE Std 1003.1-2001, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.) LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES . ASYNCHRONOUS EVENTS
Default. STDOUT
The fuser utility shall write the process ID for each process using each file given as an operand to standard output in the following for- mat: "%d", <process_id> STDERR
The fuser utility shall write diagnostic messages to standard error. The fuser utility also shall write the following to standard error: * The pathname of each named file is written followed immediately by a colon. * For each process ID written to standard output, the character 'c' shall be written to standard error if the process is using the file as its current directory and the character 'r' shall be written to standard error if the process is using the file as its root directory. Implementations may write other alphabetic characters to indicate other uses of files. * When the -u option is specified, characters indicating the use of the file shall be followed immediately by the user name, in parenthe- ses, corresponding to the process' real user ID. If the user name cannot be resolved from the process' real user ID, the process' real user ID shall be written instead of the user name. When standard output and standard error are directed to the same file, the output shall be interleaved so that the filename appears at the start of each line, followed by the process ID and characters indicating the use of the file. Then, if the -u option is specified, the user name or user ID for each process using that file shall be written. A <newline> shall be written to standard error after the last output described above for each file operand. OUTPUT FILES
None. EXTENDED DESCRIPTION
None. EXIT STATUS
The following exit values shall be returned: 0 Successful completion. >0 An error occurred. CONSEQUENCES OF ERRORS
Default. The following sections are informative. APPLICATION USAGE
None. EXAMPLES
The command: fuser -fu . writes to standard output the process IDs of processes that are using the current directory and writes to standard error an indication of how those processes are using the directory and the user names associated with the processes that are using the current directory. RATIONALE
The definition of the fuser utility follows existing practice. FUTURE DIRECTIONS
None. SEE ALSO
None. 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 FUSER(P)
All times are GMT -4. The time now is 05:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy