Manipulate files with find and fuser not working as expected on SunOs


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Manipulate files with find and fuser not working as expected on SunOs
# 1  
Old 11-03-2017
Manipulate files with find and fuser not working as expected on SunOs

Greetings,

For housekeeping, I use the following command:

Code:
find /some/path -type f -name "*log*" ! -exec fuser -s "{}" 2>/dev/null \; -exec ls -lh {} \;

It finds all log files not currently in use by a process and manipulates them.

This command always works on linux and redhat machines, however, when used on SunOs, it works for some files and for some not.

For example, logs which are not currently used by some processes get printed, From 3 logs which are being used, only one gets printed. So I cannot use gzip or rm with the find command. And I do not understand why it working partially?

Can you help me by suggesting workarounds for the command or via some alternative way?
Thanks in advance.
This User Gave Thanks to dampio For This Post:
# 2  
Old 11-03-2017
SunOS (Solaris) is not Linux. Don't expect Linux utilities to have the same behaviour as Solaris utilities of the same name. Have you checked the man page for fuser on Solaris?
Solaris:
Code:
     -s sig   Sends a signal to  each  process.  The  sig  option
              argument   specifies  one  of  the  symbolic  names
              defined in the  <signal.h>  header,  or  a  decimal
              integer  signal number.  If sig is a symbolic name,
              it is recognized  in  a  case-independent  fashion,
              without the SIG prefix. The -k option is equivalent
              to -s KILL or -s 9. No signals will be sent to ker-
              nel file consumers.

Linux:
Code:
       -s, --silent
              Silent  operation.  -u and -v are ignored in this mode.  -a must
              not be used with -s.

You will have to change the way fuser is called in the Solaris version.

Personally I would be inclined to write a script; something like:
Code:
for file in "$@"
do
   fuser "${file}" >/dev/null 2>&1 || ls -lh "${file}"
done

and call it, say, checklog, and then modify the find thus:
Code:
find /some/path -type f -name "*log*" -print | xargs checklog

Andrew

Last edited by apmcd47; 11-06-2017 at 05:50 AM.. Reason: forgot the pipe in find ... xargs line
This User Gave Thanks to apmcd47 For This Post:
# 3  
Old 11-07-2017
Quote:
Originally Posted by apmcd47
SunOS (Solaris) is not Linux. Don't expect Linux utilities to have the same behaviour as Solaris utilities of the same name. Have you checked the man page for fuser on Solaris?
Solaris:
Code:
     -s sig   Sends a signal to  each  process.  The  sig  option
              argument   specifies  one  of  the  symbolic  names
              defined in the  <signal.h>  header,  or  a  decimal
              integer  signal number.  If sig is a symbolic name,
              it is recognized  in  a  case-independent  fashion,
              without the SIG prefix. The -k option is equivalent
              to -s KILL or -s 9. No signals will be sent to ker-
              nel file consumers.

Linux:
Code:
       -s, --silent
              Silent  operation.  -u and -v are ignored in this mode.  -a must
              not be used with -s.

You will have to change the way fuser is called in the Solaris version.

Personally I would be inclined to write a script; something like:
Code:
for file in "$@"
do
   fuser "${file}" >/dev/null 2>&1 || ls -lh "${file}"
done

and call it, say, checklog, and then modify the find thus:
Code:
find /some/path -type f -name "*log*" -print | xargs checklog

Andrew
You were right. The interesting part is, that the same command works on Solaris also, but the fuser flags must be changed to
Code:
fuser -on

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Fuser alternative OR running fuser on a script

Hi, Not sure whether there is a fuser alternative or any better way to check for file in use or not. I am wanting to check whether files are in use or not before removing them. Using fuser, the awk seems to be giving me 'weird' output not to mention that it is giving me 2 lines instead of... (0 Replies)
Discussion started by: newbie_01
0 Replies

2. Shell Programming and Scripting

Some help with a find/fuser/gzip crontab job

Hello, I am trying to write a housekeeping that finds all .trc files older than x days in a given FS, checks if they are used and gzips them if they are not used by any process. I need to do it without calling any additional .sh script. I managed to make it work for Linux only: find .... (4 Replies)
Discussion started by: Valkov
4 Replies

3. Shell Programming and Scripting

mailx not working on SunOS 5.9

I m trying to send o/p of one file using mailx command but is not working PFB command : cat healthchecklog | mailx -s "HEALTH CHECKS" abc@jkl.com also I have checked the ps -ef for mailx which is giveing below o/p ps -ef | grep mail root 364 1 0 Jun 08 ? ... (11 Replies)
Discussion started by: Jcpratap
11 Replies

4. Shell Programming and Scripting

basename not working as expected from find -exec

I have the following files in a directory > ls -1 /tmp/test/dir/ file with spaces 1.ogg file with spaces 2.oggI am running the following to echo the filenames but alter the file extension on the files to .mp3 instead of .ogg ( I am going to run ffmpeg against the files ultimately, but keeping... (2 Replies)
Discussion started by: jelloir
2 Replies

5. Solaris

SunOs 5.9: why is 'ulimit -c' not working?

I have a situation where the system is dumping a 2g causing filesystem to fill up. We identified the source and working on a solution. However, I wanted to limit the size of the 'core' file. Please examine the test scenario ... cnewtonne@mars> ulimit -f 0 cnewtonne@mars> ls -ltr core*... (2 Replies)
Discussion started by: cnewtonne
2 Replies

6. Shell Programming and Scripting

Find files modified in last hour sunOS 5.10

trying to find a way to locate files modified in the last hour in a shell script, unfortunately the command 'find . -mmin -60' is not supported on SunOS 5.10 (works on OpenSolaris 5.11 :mad:) Does anyone know a method of doing this in shell script on 5.10? cheers (19 Replies)
Discussion started by: rich@ardz
19 Replies

7. Solaris

tr -d is not working on SunOS 5.9

i am using sunos 5.9. entityname="india\/delhi" correctpattern="<branch value=\"/`echo $entityname | tr -d '\'`/WORKAREA/\"> echo $correctpattern the output should be <branch value="/india/delhi/WORKAREA/"> This is working fine in command line but not working when i placed these... (1 Reply)
Discussion started by: millan
1 Replies

8. Shell Programming and Scripting

Find cmd not working as expected

Hi, i wan to search the file starting with Admin into the directory Output. I am running below command: find /appl/Output -name "Admin*" -prune but this command is going into the sub directories present under output. I do not want to search under sub directories. Any help will be highly... (6 Replies)
Discussion started by: Vishal123
6 Replies

9. UNIX for Dummies Questions & Answers

Find command not working as expected

I have a script with a find command using xargs to copy the files found to another directory. The find command is finding the appropriate file, but it's not copying. I've checked permissions, and those are all O.K., so I'm not sure what I'm missing. Any help is greatly appreciated. This is... (2 Replies)
Discussion started by: mpflug
2 Replies

10. Shell Programming and Scripting

awk not working as expected with BIG files ...

I am facing some strange problem. I know, there is only one record in a file 'test.txt' which starts with 'X' I ensure that with following command, awk /^X/ test.txt | wc -l This gives me output = '1'. Now I take out this record out of the file, as follows : awk /^X/ test.txt >... (1 Reply)
Discussion started by: videsh77
1 Replies
Login or Register to Ask a Question