Skip files in use


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Skip files in use
# 8  
Old 08-29-2012
Parse the output, maybe with awk and build your exclude list with this.
But as RudiC already mentioned, the information can be very short-lived and also a file can be in use right after you gathered your list.
# 9  
Old 08-29-2012
In bash, you could use (excerpt from man bash):
Code:
... extended pattern matching operators ...
pattern-list is a list of one or more patterns separated by a |.
...
!(pattern-list)
                     Matches anything except one of the given patterns

So - create a "|" separated lsof pattern list in a variable and use the !($var) operator to exclude those files from processing.
# 10  
Old 08-30-2012
well till here its ok,
Code:
#!/bin/sh

lsof -p `ps -elf | grep tomcat | grep -v grep | grep -v monitor | awk {'print $4'}` | grep "/var/log" | awk {'print $9'} > "/tmp/mylogs.txt"

but i need to find everything that is not on that file on a specific folder

find find /var/log/myfolder/ --exclude from /tmp/mylogs.txt -type f -mtime +1 -exec gzip {} \;
Any one could make an example of the script, please?
# 11  
Old 08-30-2012
No need for that long contruct; given you are using bash, try this to ls all files in /var/log NOT open by the command "sleep":
Code:
ls -d /var/log/!($(lsof -Fn -c sleep  2>/dev/null|awk -F"[/]" '/\/var\/log/{printf "%s|",$4}'))

What it does: lsof outputs the open files for command sleep, including path, which is removed by awk, adding the "|" separator. This then goes into the bash extglob operator !(...) to be used by ls.
# 12  
Old 08-30-2012
Quote:
Originally Posted by RudiC
No need for that long contruct; given you are using bash, try this to ls all files in /var/log NOT open by the command "sleep":
Code:
ls -d /var/log/!($(lsof -Fn -c sleep  2>/dev/null|awk -F"[/]" '/\/var\/log/{printf "%s|",$4}'))

What it does: lsof outputs the open files for command sleep, including path, which is removed by awk, adding the "|" separator. This then goes into the bash extglob operator !(...) to be used by ls.
it is not a bash,
so the error is
Code:
event not found

.
# 13  
Old 08-31-2012
If the error is what you post (I had the same during testing), there is a chance it will understand a slight modification of above. Assign the $(lsof ...) stuff to a variable and try /var/log/!($var). Follow up with option -x set.
# 14  
Old 08-31-2012
Quote:
Originally Posted by RudiC
If the error is what you post (I had the same during testing), there is a chance it will understand a slight modification of above. Assign the $(lsof ...) stuff to a variable and try /var/log/!($var). Follow up with option -x set.
Thanks for trying to help,i'm working on it,

not solved yet.

will update later...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can I skip files when running rm command

Platform: Oracle Enterprise Linux 6.2 I have several files like below. I want to remove all files except one file For example , I want to remove all the files below except dasd_91197.trc $ ls -alrt *.trc -rw-r----- 1 ecmdev wms 8438784 May 7 21:30 dasd_91177.trc -rw-r----- 1 ecmdev wms ... (3 Replies)
Discussion started by: John K
3 Replies

2. Shell Programming and Scripting

Skip first and last line

Hi All I have a sample file like below: 012312112 1372422843 1236712 1372422843 1275127 3109301010 from which I wan't to: 1.)delete... (10 Replies)
Discussion started by: swasid
10 Replies

3. Shell Programming and Scripting

How to skip copying some types of files in csh

Hi, I want to copy data from one directory to another in csh script. But in that i want to skip certain types of file. How can i do that. Currently i am copying all the files as mentioned below.. foreach d ( $TEST_PATH/*) cp -R $d $PWD end now i want to skip files... (3 Replies)
Discussion started by: vdhingra123
3 Replies

4. Shell Programming and Scripting

Skip first and last n records with awk

Hi, I have an awk code that reads an input file, checks the 4th column and tells if its fine. #!/bin/ksh { if ($4 == 0) print "fine" else print "some problem" }' FILENAME My problem is that, I dont want to check the first 3 and last 3 lines. This can be hard coded by using BEGIN and END... (9 Replies)
Discussion started by: gotam
9 Replies

5. Programming

How to skip getchar in C?

Hi, I would like to read an input from keyboard using getchar. However, if no input (No Carriage return/new line none whatsoever) is given after say, 5 seconds, I would like to skip the getchar and move on. How do I do this in C. I'm using GNU compiler set. Thanks, (5 Replies)
Discussion started by: cprogdude
5 Replies

6. Shell Programming and Scripting

go to / skip in script

Hi all I have some script like this #!/bin/bash mv /tmp/file1 tmp/file2 if ] ; then cp /tmp/filetest/ tmp/file3 if ] then echo "succes" else echo "failed" fi else echo "failed" fi i didn't try to see if it's work, the thing is that i don't care if... (4 Replies)
Discussion started by: naamas03
4 Replies

7. Shell Programming and Scripting

extract multiple cloumns from multiple files; skip rows and include filenames; awk

Hello, I am trying to write a bash shell script that does the following: 1.Finds all *.txt files within my directory of interest 2. reads each of the files (25 files) one by one (tab-delimited format and have the same data format) 3. skips the first 10 rows of the file 4. extracts and... (4 Replies)
Discussion started by: manishabh
4 Replies

8. SuSE

skip upgrading rpm

hi the step 'upgrading the rpm' is taking a long tme. and since I am not interested in uninstallation, is there a way to skip this step? thx (4 Replies)
Discussion started by: melanie_pfefer
4 Replies

9. Shell Programming and Scripting

Skip new line

Hi, how can I skip the new line of echo? In SH!!!! echo "the date is :" date and result I want is the date is : Tue Oct 11 22:24:37 WEST 2005 I've already tried including the \c inside the echo, but it didn't work. Thanks! (2 Replies)
Discussion started by: pmpx
2 Replies

10. BSD

FreeBSD skip UserConfig...

When I boot FreeBSD from cd/floppy, it skips the UserConfig program. I have no idea why! And if I skip this step, my hardware won't work. ( I already tried...) Can anyone help me with this??? (2 Replies)
Discussion started by: Enoch Chan
2 Replies
Login or Register to Ask a Question