Redirecting 'find' output...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Redirecting 'find' output...
# 1  
Old 10-15-2008
Redirecting 'find' output...

Hi all, why does one version of this command work but not the other?

- This file already exists [/users/d269836/scripts.txt] with 644 mod permissions
- I am logged in as d269836, no su rights.
- Box is 'SunOS' running bash I think; but runs ksh scripts OK.

This one works:
Code:
find /users/d269836 -type f -name "*.txt" >> /users/d269836/scripts.txt

...and yet these code examples append nothing to scripts.txt:
Code:
find /users/ -type f -name "*.txt" >> /users/d269836/scripts.txt
find /users/. -type f -name "*.txt" >> /users/d269836/scripts.txt
find / -type f -name "*.txt" >> /users/d269836/scripts.txt

Note that all commands produce the expected output (on stdout) when not redirected to scripts.txt. Hence the weirdness?
UPDATE: Also, these commands work fine if not appended to scripts.txt (just redirected) like so:
Code:
find / -type f -name "*.txt" > /users/d269836/scripts.txt

Am I losing my mind here?? This is starting to smell implementation-dependent...

Here is the original code I'm trying to make work - but it fails accordingly to above pattern.
Code:
find / -type f -name "*.ksh" >> /users/d269836/scripts.txt
find / -type f -name "*.sh" >> /users/d269836/scripts.txt


Last edited by dan-e; 10-15-2008 at 11:46 PM.. Reason: New information added
# 2  
Old 10-16-2008
Add "-print" to it - maybe it helps.
# 3  
Old 10-16-2008
Quote:
Originally Posted by zaxxon
Add "-print" to it - maybe it helps.
...well it now outputs the full path of every file it tests, rather than the ones I'm filtering for...

Have I just found a bug in the illustrious 'NIX? Can anyone reproduce (or not) what I have described in the original post? Is this a common variety of glitch in ux? Smilie

Im scared!! and I need answers!!!
# 4  
Old 10-16-2008
Quote:
Originally Posted by dan-e
...well it now outputs the full path of every file it tests, rather than the ones I'm filtering for...

Have I just found a bug in the illustrious 'NIX? Can anyone reproduce (or not) what I have described in the original post? Is this a common variety of glitch in ux? Smilie

Im scared!! and I need answers!!!
Unless I'm missing something here (that happens rather often unfortunately Smilie), your command doesn't actually instruct find to display the output but instead relies on a bit of smarts find has that prints what it matches if stdout is not redirected... I'd not have expected the first one (that does work) to work correctly either Smilie

As suggested by zaxxon, add a -print or -ls to actually output the name on stdout.
If it's showing every file, I would guess you have the -print before the rest of the tests (it does them in order, -print and -ls always return true).
# 5  
Old 10-16-2008
OK! Good advice guys... but the mystery is still unsolved.

Adding -print to the end of the command did fix the issue with all file names being output (cheers zaxxon), like so:
Code:
find / -type f -name "*.ksh" -print

... now I get only the files I care about, but it still won't append the output to file! It will redirect to the file, but not append.

Any clues to that end? Is it possible to disable append-redirection?

Here's a handy take-home pack of the BS I am experiencing:
Code:
qmmm1#cat testfind.sh                                               | < My little script
find / -type f -name "*.tar" -print>tars.txt                        | < Find em once and dump to file
pwd >> tars.txt                                                     | < ...just to make a mark in output file
find / -type f -name "*.tar" -print>>tars.txt                       | < Find em again and append to file
                                                                    |
qmmm1#cat tars.txt                                                  |
/var/opt/OV/share/snmp_mibs/Vendor/cps.tar                          | < Here they are...
/var/opt/OV/share/snmp_mibs/fsms.tar                                |
/var/opt/OV/conf/OpC/qmmm1.tar                                      |
/var/agent/OPC/root/opt/OV/lib/perl/perl.tar                        |
/opt/OV/contrib/NNM/Cisco/CW2K/hpovwebintegrate1.2.0-sol-rme2.0.tar |
/opt/OV/lib/perl/perl.tar                                           |
/opt/OV/newconfig/OVWIN-BGROUND/backgrounds.tar                     |
/opt/hpxt/enware2/enware2.tar                                       |
/users/dgarnsly/PSOV_03238.tar                                      |
/users/f845073/qqc1_mysql.tar                                       |
/users/f845073/qcct2_templates_20060228.tar                         |
/users/c745073/qcct2_templates_20060301.tar                         |
/users/mnams/qmmm1.tar                                              |
/users/c675133/fixed.tar                                            |
/.cpan/build/Archive-Tar-1.04/t/src/long/bar.tar                    |
/.cpan/build/Archive-Tar-1.04/t/src/short/bar.tar                   |
/users/d269836                                                      |< Here's my bookmark
qmmm1#                                                              |< ...um where's the rest?


Last edited by dan-e; 10-17-2008 at 12:35 AM.. Reason: Code sample added
# 6  
Old 10-17-2008
Now that's strange. Try it in another kind of shell maybe ie. if you use bash use ksh or vice versa.

Does this happen even if you start a file with redirecting a simple echo and adding more with >> on echoes?
# 7  
Old 10-17-2008
MySQL Yes it is strange!

Problem Solved.Smilie

Logged in as root, worked from /tmp and repeated commands - all fine.

The underlying cause?Smilie
Disk space quota busted under my login d269836. Apparently my quota was ~5kb.

Which is annoying. But not as annoying as multiple commands failing Smilie & negating to mention whySmilieSmilie, or so much as notify ANY failureSmilieSmilieSmilie.

Aaaaanyway, cat saved me! And these forums! Smilie here's how:
Code:
qmgt1#cat scripts.txt                                                    |< So wats in there this time...
/usr/demo/link_audit/src/perfcnt.ksh                                     |
/usr/demo/link_audit/src/sotruss.ksh                                     |
/usr/demo/link_audit/src/symbindrep.ksh                                  |
/usr/demo/link_audit/src/whocalls.ksh                                    |
/usr/dt/appconfig/sdtpdasync/lib/maxbaud.ksh                             |< ... k some files... not many.
/usr/dt/appconfig/SUNWns/checkJRE.ksh                                    |
/var/opt/OV/bin/OpC/cmds/gprs_gsn.ksh                                    |
/var/opt/OV/bin/OpC/cmds/cdma_outage.ksh                                 |
/var/opt/OV/bin/OpC/monitor/check_bsm.ksh                                |
/opt/sfw/lib/mozilla/checkJRE.ksh                                        |
/users/dgarnsly/SUNWnsb/reloc/dt/appconfig/SUNWns/checkJRE.ksh           |
/users/dgarnsly/mozilla1-4/SUNWmoznav/reloc/sfw/lib/mozilla/checkJRE.ksh |
/users/dgarnsly/mozilla1-4/checkJRE.ksh                                  |
/users/dgarnsly/sdm/SUNWmoznav/reloc/sfw/lib/mozilla/checkJRE.ksh        |
/users/dgarnsly/sdm/checkJRE.ksh                                         |
/users/r845073/SUNWmoznav/reloc/sfw/lib/mozilla/checkJRE.ksh             |
/users/r845073/checkJRE.ksh                                              |
/my_backup.ksh                                                           |
qmmm1#cat scripts.txt >> s2                                              |< Sanity check on >> operator.
qmmm1#cat scripts.txt >> s2                                              |< (I don't trust my sanity anymore)
cat: write error: No space left on device                                |< Apparently for good reason!
qmmm1#cat s2 > s3                                                        |< NFI how that works..??:confused:
qmmm1#cat s2 >> s3                                                       |
cat: write error: No space left on device                                |< ah, it's time to search unix.com
                                                                         | this is the first 'error' i've seen!

If anyone has an explanation for my NFI section in the code above, I'm dying to be humoured! Thanks all for your assistance...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirecting output using if with awk

I have this line were I am selecting some fields from one file and creating a new file for the selected data. awk -F "\"*,\"*" '{print $1"," $2}' folderone/list.txt > folderone/qlist.txt This works, but then from this new file I want it to create a new file where it separates data: $2 >5 it... (2 Replies)
Discussion started by: rluna
2 Replies

2. Shell Programming and Scripting

Redirecting the output

For example, if we run the below command, symcfg list -thin -pool , results in an output most of the times and if the out is generated i'm able to redirect the output to a file. but sometimes it doesnt result any output and even though the output is being redirected, i can see "No Thin Pools "... (2 Replies)
Discussion started by: web2moha
2 Replies

3. Shell Programming and Scripting

redirecting output using if-then-else in awk

I am trying to filter records based on number of "|", delimiter in my application. If number of "|" is greater than 14 its a bad record, else its a good record. I have to redirect output to two different files based on the if-then-else evaluation in AWK. if number of “|” in file_0 > 14 ... (2 Replies)
Discussion started by: siteregsam
2 Replies

4. Shell Programming and Scripting

find: missing argument to `-exec' while redirecting using find in perl

Hi Friends, Please help me to sort out this problem, I am running this in centos o/s and whenever I run this script I am getting "find: missing argument to `-exec' " but when I run the same code in the command line I didn't find any problem. I am using perl script to run this ... (2 Replies)
Discussion started by: ramkumarselvam
2 Replies

5. UNIX for Dummies Questions & Answers

redirecting script output

Hello, I am interested in taking the output from a script i wrote and using it as input to a different script i wrote. So for example i want to take the output from program2 and use it as a parameter for program1. I didnt think i could use the >> symbols because i think that is just for .txt... (4 Replies)
Discussion started by: GmGeubt
4 Replies

6. Shell Programming and Scripting

Redirecting output to file

Hi, Below is the whole string which is to be redirected to the new file. su - oracle -c "exp $user/$pass file=/oracle/oradata/backup/exp_trn_tables_`date +%d_%b_20%y_%H_%M_%S`.dmp log=/oracle/oradata/backup/exp_trn_tables_`date +%d_%b_20%y_%H_%M_%S`.log tables=table1,table2 statistics=none" ... (3 Replies)
Discussion started by: milink
3 Replies

7. Shell Programming and Scripting

help redirecting output from mailbot

Hello...I'm having problems redirecting output from a script from a mailbot. It is a perl script that has the email sent to op_shipper piped into it. I am receiving the email with sendmail and here is what my alias looks like for the script am I having problems with in /etc/aliases: ... (3 Replies)
Discussion started by: kuliksco
3 Replies

8. Shell Programming and Scripting

Redirecting OUTPUT

Hi, I want to move the output of a command/script to a file as well as to to be displayed on stdout. Can anybody help me in this. Thanks in advace .. -Chanakya M (1 Reply)
Discussion started by: Chanakya.m
1 Replies

9. UNIX for Advanced & Expert Users

redirecting the output of aspell

Hi, I have 2 identical servers both running aspell but for some reason I can't redirect the output to a file on one of them. This is what I'm trying to do: echo feck | aspell -l > errors.txt On one machine this works fine but the other it doesn't (the file is created but it is empty). ... (6 Replies)
Discussion started by: leekb
6 Replies

10. UNIX for Dummies Questions & Answers

Redirecting the startup output

Is there any way to redirect the output of the startup of a sun E250. Im basically trying to troubleshoot some init scripts and it would be useful to have a log of the startup output. (3 Replies)
Discussion started by: blakmk
3 Replies
Login or Register to Ask a Question