-1

we have redhat 7.2 Linux version

I want to remove on remote machines all repositories files under /etc/yum.repos.d except the following files under /etc/yum.repos.d

local.repo
redhat.repo
cluster.repo

we tried this ( but without success )

ssh root@$machine find /etc/yum.repos.d  -type f -not -name 'local.repo ' -or -name 'redhat.repo' -or -name ' cluster.repo’  –delete

or

ssh root@$machine find /etc/yum.repos.d  ! -name 'local.repo|redhat.repo|cluster.repo' -type f -exec rm -f {} +

or

ssh root@$machine find   /etc/yum.repos.d -type f -not \(-name 'local.repo'  -or -name 'redhat.repo' -or -name 'cluster.repo' \) -delete
terdon
  • 242,166
yael
  • 13,106

2 Answers2

3
ssh "root@$machine" '
   find /etc/yum.repos.d -type f ! \(
     -name local.repo -o \
     -name redhat.repo -o \
     -name cluster.repo \) –delete
'

(assuming the login shell of the root user on $machine is Bourne-like).

Remember what you're passing to ssh is not the arguments of a command to run on the remote host, but a string that is interpreted as shell code by the login shell of the remote user. So the easiest is to put that string inside single quotes so the local shell doesn't interfere with it.

0

this CLI will remove all files under /etc/yum.repos.d , exclude the files , and also will print the files that are deleted

ssh "root@$IP" "find  /etc/yum.repos.d ! -name local.repo ! -name redhat.repo ! -name cluster.repo    -type f -delete -print"
yael
  • 13,106