I'm scanning for all shell scripts on my server, and are doing this by the following command:

find / -type f -exec file --mime-type {} \; | grep "text/x-shellscript"

This is working fine, and here is a sample output from this:

/lib/udev/hwclock-set: text/x-shellscript
/lib/init/bootclean.sh: text/x-shellscript
/etc/network/if-up.d/openssh-server: text/x-shellscript
/etc/network/if-up.d/mountnfs: text/x-shellscript

Now, I want to work on the filenames, and try to use awk for this:

find / -type f -exec file --mime-type {} \; | grep "text/x-shellscript" | awk -F: '{ print $1 }'

This however, does not produce any output. Ive tried redirecting pipes etc, but here I've hit the wall.

Anyone have an idea of what I'm doing wrong?

link|improve this question
What happens with echo "/etc/network/if-up.d/mountnfs: text/x-shellscript" | awk -F: '{ print $1 }'? – Daniel Beck Oct 16 '11 at 13:51
@DanielBeck That works. Maybe find does not write to stdout? But then I can't explain how grep to do its part... – Dog eat cat world Oct 16 '11 at 13:53
You can redirect error output to standard output. Your command will then look like this: find / -type f -exec file --meta-type {} \; | grep "text/x-shellscript" 2>&1 | awk -F: '{ print $1 }' – Daniel Beck Oct 16 '11 at 14:03
@DanielBeck No, it does not help. I've tried "find / -type f -exec file --mime-type {} \; | grep "text/x-shellscript" 2>&1 1>this_file_should_not_be_empty", but it seems like grep is outputting to nowhere! Even if the text is displayed on the monitor without pipe redirection. – Dog eat cat world Oct 16 '11 at 14:20
You can narrow your problem locus, and get rid of one of those tags on the question, by eliminating the useless use of grep there. – JdeBP Oct 16 '11 at 15:41
show 2 more comments
feedback

1 Answer

Try this:

  find / -type f -exec file --meta-type {} \; | grep "text/x-shellscript" | cut -d: -f 1
link|improve this answer
Thanks, this works. But I'm still curious why awk doesn't – Dog eat cat world Oct 16 '11 at 13:54
Your awk command works fine here, there's nothing wrong with it. If you're embedding this pipe into some other command (backticks, etc.) then the only difference I can think of is the single quotes you use in awk command. – haimg Oct 16 '11 at 14:00
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.