Trying to remove directories from server:
ssh myname@servera ssh othername@serverb find /var/lib/jenkins/some/path/to/check -name 2.2.4* -type d -exec rm -r {} ;
I tried with ;
and ;;
and ;
and "{}"
and -exec sh -c 'rm -r "{}"' ;
All get’s the error find: missing argument to "-exec'"
Thanks
Advertisement
Answer
Directly running commands with ssh is often hard to impossible when you want to use special characters. This is because ssh remotely calls sh -c "<<COMMAND HERE>>"
. This causes the characters to be quoted / unquoted twice and sometimes even removed.
Your best option is to create a tempfile with your command on the remote system and execute it:
echo 'find /var/lib/jenkins/some/path/to/check -name 2.2.4* -type d -exec rm -r {} ;' > script scp script myname@servera: ssh myname@servera bash script
In your case, you may use find’s -delete
command instead of -exec
.