Попробуйте:
find. \! \( -wholename "./build/*" -o -wholename./build \) -delete
Если вы запустите:
rm -rf /tmp/tmp2
mkdir /tmp/tmp2
cd /tmp/tmp2
mkdir -p build module/build source
touch.hidden build/abc build/abc2 source/def module/build/ghi
find. \! \( -wholename "./build/*" -o -wholename./build \) -delete
find.
ваш вывод будет:
./build
./build/abc
Это намного безопаснее, чем пытаться разобрать вывод ls
, где вам нужно позаботиться об именах файлов или каталогов с пробелами или, что еще хуже, со встроенными символами новой строки, find
обрабатывает их правильно.
Попробуйте просто сказать первому хосту выполнить команду ssh
вместо того, чтобы давать вам оболочку:
ssh -t -i private_key.pem ec2-user@ec2-11-11-111-11.us-west-2.compute.amazonaws.com ssh -t second_aws
То, что вы делаете, не открывает второе соединение из вашего экземпляра AWS. Он открывает соединение из того места, где запускается скрипт.
Вам следует искать опцию ProxyJump
. Это позволит вам связать несколько SSH-соединений.
Вот выдержка со страницы man
:
ProxyJump
Specifies one or more jump proxies as either [user@]host[:port] or an ssh URI. Multiple proxies may be separated by comma characters and will be visited sequentially. Setting this option will cause ssh(1) to connect
to the target host by first making a ssh(1) connection to the specified ProxyJump host and then establishing a TCP forwarding to the ultimate target from there.
Note that this option will compete with the ProxyCommand option - whichever is specified first will prevent later instances of the other from taking effect.
Note also that the configuration for the destination host (either supplied via the command-line or the configuration file) is not generally applied to jump hosts. ~/.ssh/config should be used if specific configuration
is required for jump hosts.