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 application.
Correct me if I am wrong any where.. This coding is to find the top 3 files in the filesystem with respect to size.

#!/usr/bin/perl
$get_filename=qx("find / -mmin 1 -type f -exec ls -lh {} \; 2>  /dev/null | awk '{ print $NF ": " $5 }'  | sort -nrk 2,2 |head -n3");
print "$get_filename \n";

Your feedback is appreciated on this

It's probably eating the backslash since perl double-quotes evaluate those. You may need to escape the escaping. You'll probably also need to escape those $ in your awk, since perl evaluates those into variables, and escape the double-quotes i the awk statement, so perl won't mistake them for its own.

I remember writing Perl like that: Line after line after line of nothing but system() and backticks. Eventually I noticed they were starting entire bourne shells just to parse one "mv a b" and was horrified -- by avoiding the shell I'd actually used eight of them consecutively :wall:

Returning much later, I rewrote some of these "perl" scripts as shell, making them much smaller, simpler, and saner.

$ wc -l dispatch.pl
49 dispatch.pl
$ wc -l dispatch.sh
25 dispatch.sh
$
1 Like
  • First thought: Why in the world is this a perl script?
  • Second thought: don't use ls -h: some files might have a suffix of M; some G (etc). No good.
  • Third thought: Why are you doing this? Whatever the reason, I think there has got to be a better way. You do not need to be searching your WHOLE filesystem every minute (I'm assuming that's what you're doing based on your find options). With the limited info you've given, I think you would be much better off installing inotify-tools (available in every major distro) and watching only the directories that things are being created in.