Knife command fails

The following knife command works fine (where $z is a variable read in from the command line):

knife ssh name:$z ‘sudo chmod 777 /trashfile’ -x myaccount -i ~/.ssh/mykey.pem -C 3

Now the following command (very similar to the above) fails:

knife ssh name:$z ‘sudo find /file/in/some/path -type f -ctime +3 | xargs -n1 rm -f’ -x myaccount -i ~/.ssh/mykey.pem -C 3

The second command fails with the following error:

“cannot remove /file/in/some/path” permission denied"

Note, I’m using sudo, and the first command works. Why does the second one fail?

Could it be the “pipe” (|)?? If so, is there a way around that?


Yep, it's the pipe. Kinda wonky, but if you run sudo whoami | whoami you should get your username and not root.

For your example, probably the cleanest way to go is to use find's -exec option, though you could add another sudo after the pipe (e.g., sudo whoami | sudo whoami works).

Works for me. Thanks much.