1

when I'm trying to use this command

var1=`sudo -u psoadmin -H -s ssh [email protected] find . -maxdepth 1 -type f -mtime +14 -exec ls -lh  \{} \; | awk '{print $5, $9}'|egrep -v '^./upload|^./download|^./archive|^\.'`

it is throwing me as

find: missing argument to `-exec'

Please let me know if i made any mistakes in this.

3 Answers 3

3

You've got too many shells doing some processing in there. Also, using backticks is a bad idea especially when there's going to be backslashes in them. You should use the $(...) syntax instead.

sudo -s starts a shell to run the command, but with sudo trying to escape some of the special characters for the shell. You don't want to use that.

ssh runs a shell on the remote host to interpret the command line that is made of the concatenation of the arguments (with space in between).

So in:

var1=`sudo -u psoadmin -H -s ssh [email protected] find . -maxdepth 1 -type f -mtime +14 -exec ls -lh  \{} \;`

sudo runs:

"/bin/bash", ["/bin/bash", "-c", 
  "ssh daill_scp\\@files.dc1.responsys.net find \\.  -maxdepth 1 -type f -mtime \\+14 -exec ls -lh \\{\\} \\;"]

(/bin/bash or whatever the login shell of the user is).

Notice how sudo escaped ., +, }, but not backslash for no particularly good reason.

Then that bash will run:

"/usr/bin/ssh", ["ssh", "[email protected]", "find", ".", "-maxdepth", "1", "-type", "f", "-mtime", "+14", "-exec", "ls", "-lh", "{}", ";"]

ssh will concatenate those and run on remote host:

"$SHELL", ["$SHELL", "-c", "find . -maxdepth 1 -type f -mtime + 14 -exec ls -lh {} ;"]

(where $SHELL is the login shell of the remote user this time).

That ; above is not escaped, so interpreted as a command separator and not passed to find which is why find complains that that -exec is not terminated.

Here, you want:

var1=$(
  sudo -u psoadmin -H ssh [email protected] '
    find . -maxdepth 1 -type f -mtime +14 -exec ls -lh {} \;' |
    awk '{print $5, $9}' |
    egrep -v '^./upload|^./download|^./archive|^\.'
)

(not that that command (especially the egrep part) makes a lot of sense).

1
  • Awesome!! Really great! It worked!Thanks a lot
    – user105264
    Mar 31, 2015 at 8:54
0

Try on this way:

...-exec ls -lh {} \;...

(remove backslash before curly bracket) Double quotes:

var1=`sudo -u psoadmin -H -s ssh [email protected] "find . -maxdepth 1 -type f -mtime +14 -exec ls -lh  {} \; "| awk '{print $5, $9}'|egrep -v '^./upload|^./download|^./archive|^\.'`
6
  • I tried that also but it did not work...It is throwing same error "find: missing argument to `-exec'"
    – user105264
    Mar 31, 2015 at 6:35
  • Have you put the entire find in double quotes as it need to be executed on remote site? Mar 31, 2015 at 6:37
  • I tried now, It did not work:( its throwing me syntax error!
    – user105264
    Mar 31, 2015 at 6:40
  • I edit my answer with example, try it on this way Mar 31, 2015 at 6:40
  • And as you can do sudo what is the reason do not get the key from psoadmin user and use it w/o sudo? Mar 31, 2015 at 6:43
0

when I'm trying to use this command

var1=`sudo -u psoadmin -H -s ssh [email protected] find . -maxdepth 1 -type f -mtime +14 -exec ls -lh  \{} \; | awk '{print $5, $9}'|egrep -v '^./upload|^./download|^./archive|^\.'`

it is throwing me as

find: missing argument to `-exec'

You should use this:

var1=`sudo -u psoadmin -H -s ssh [email protected] "find . -maxdepth 1 -type f -mtime +14 -exec ls -lh  {} \;  | tr -s [:space:] | cut -d ' ' -f 5,9 | egrep -v '^./upload|^./download|^./archive|^\.'"`
  1. Use "find [..]"
  2. Use tr

    -s, --squeeze-repeats
          replace each input sequence of a repeated character that is listed in SET1 with a single occurrence of that character
    
  3. Use cut

    -d, --delimiter=DELIM
          use DELIM instead of TAB for field delimiter
    -f, --fields=LIST
          select only these fields;  also print any line that contains no delimiter character, unless the -s option is specified
    
7
  • I tried this also,Again im getting same error message"find: missing argument to `-exec'";(
    – user105264
    Mar 31, 2015 at 8:17
  • Which shell is running on the server?
    – A.B.
    Mar 31, 2015 at 8:20
  • I just tried in another way as var1=sudo -u psoadmin -H -s ssh [email protected] find /home/cli/daill_scp -maxdepth 1 -mtime +14 -printf '%k %p\n' |egrep -v '^upload|^download|^archive|^\.'
    – user105264
    Mar 31, 2015 at 8:29
  • But this also did not work
    – user105264
    Mar 31, 2015 at 8:29
  • find: paths must precede expression Usage: find [-H] [-L] [-P] [path...] [expression] it throws error like above mentioned
    – user105264
    Mar 31, 2015 at 8:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .