Xargs or Find with output to a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Xargs or Find with output to a file
# 1  
Old 10-24-2012
Xargs or Find with output to a file [SOLVED]

Hi,

I've got to setup a script that will run daily, and find a log file of a certain age, and then compress and transfer this file to a new location.

so far i've been able to specify the file i want with:

Code:
find . -name 'filename.*.log' -mtime 14 -exec compress -vf  {} \;

this prints out to screen the % of compression etc.

I'd like to sent this information to a file, and then email it out to users to show the file compression/backup has worked. however when i try to enter other code for this after the .\ i get an "find: incomplete statement"

i've also tried with now avail:

Code:
find . -name 'filename.*.log' -mtime 10 | xargs compress -vf > file.txt

any help greatly appreciated!

Last edited by horhif; 10-26-2012 at 06:13 AM.. Reason: solved
# 2  
Old 10-24-2012
Code:
find . -name 'filename.*.log' -mtime 14 -exec compress -vf  {} \; > file.txt

This User Gave Thanks to elixir_sinari For This Post:
# 3  
Old 10-25-2012
this seems to output the compression to screen, and doesn't send it to the file.

thanks
# 4  
Old 10-26-2012
The output from the compress utility's -v option is written to standard error; not to standard output. Try this minor change to elixir_sinari's suggestion:
Code:
find . -name 'filename.*.log' -mtime 14 -exec compress -vf  {} \; 2> file.txt

This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 10-26-2012
that did it, thanks very much guys!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pipe output a command to another using xargs

xargs work great when a command gives multiple line output which can be input to another. In my case it is not working coz the second command uses two words in it. $ scr.sh gives output like 193740 638102 375449 .. .. another command takes these number as inputs. it works great... (1 Reply)
Discussion started by: mahesh113
1 Replies

2. Shell Programming and Scripting

Help with find, xargs and awk

Hi, I want to find some files and then search for some lines in it with a particular pattern and then write those lines into a file. To do this I am using something like this from command prompt directly. cd /mdat/BVG find -name "stmt.*cl" -newer temp.txt | xargs -i awk '/BVG-/{print}' {} >... (7 Replies)
Discussion started by: Sandhya Harsh
7 Replies

3. UNIX for Dummies Questions & Answers

find/xargs/*grep: find multi-line empty "try-catch" blocks - eg, missing ; not in a commented block

How can I recursively find all files in a directory and print out the file and first line number of any text blocks that match the below cases? This would seem to involve find, xargs, *grep, regex, etc. In summary, I want to find so-called empty "try-catch blocks" that do not contain code... (0 Replies)
Discussion started by: lifechamp
0 Replies

4. Shell Programming and Scripting

Find common terms in two text file, xargs, grep

Hello, I'm interested in finding all occurrences of the terms in file1 in file2, which are both csv files. I can do this with a loop but I'm interested in knowing if I can also do it with the help of xargs and grep. What I have tried: cat file1 | xargs grep file2 The problem is that... (15 Replies)
Discussion started by: eon
15 Replies

5. Shell Programming and Scripting

Xargs + Find Help

Guys i want to run a command to list all directories that havn't been modified in over 548 days ( 1.5 yrs ). Id like to run a script to first print what the command finds ( so i get a list of the files pre move ... i have a script set for this : find /Path/Of\ Target/Directory/ -type d -mtime... (4 Replies)
Discussion started by: modulartention
4 Replies

6. Shell Programming and Scripting

File find | xargs grep for pattern file

Folks I've been struggling this with for far too liong now and need your help! I've been happily using grep for a search of a directory, to list the files which contain a string: find . -type f -mtime -5 -print | xargs grep -l 'invoiceID=\"12345\"' Now the list of 'invoiceID' I am... (4 Replies)
Discussion started by: daveaasmith
4 Replies

7. Shell Programming and Scripting

find and xargs

hi, i've been trying to figure this weird error but I cannot seem to know why. I am using below find command: find . \( ! -name . -prune \) -type f -mtime +365 -print The above code returns no file because no files are really more then 365 days old. However, when I use xargs, its... (9 Replies)
Discussion started by: The One
9 Replies

8. UNIX for Dummies Questions & Answers

XARGS and FIND together

I am trying to delete files older than 60 days from a folder: find /myfolder/*.dat -mtime +60 -exec rm {} \; ERROR - argument list too long: find I can't just give the folder name, as there are some files that I don't want to delete. So i need to give with the pattern (*.dat). I can... (3 Replies)
Discussion started by: risshanth
3 Replies

9. Shell Programming and Scripting

find | xargs cat

Hi, I am having trouble getting a combination of commands to work. I need to traverse through all sub-directories of a certain directory and 'cat' the contents of a particular file in the sub-directories. The commands on their own work but when I combine them I get no output. The... (4 Replies)
Discussion started by: DownunderDave
4 Replies

10. Shell Programming and Scripting

Problem using find and xargs

I'm using Imagemagick to create thumbnails for a large directory tree. The only thing I can't see is how to get it to write the thumbnails to a "thumbs" subdirectory! Either of these two commands from the Imagemagick site does most of the job: find -name '*.jpg' | xargs -n1 sh -c 'convert $0... (5 Replies)
Discussion started by: quixote
5 Replies
Login or Register to Ask a Question