Есть ли способ использовать sshfs для машины «на расстоянии двух прыжков»?

Этот должен работать, но он медленный (1 мин. 18 сек. На 500 записей)

#!/bin/bash

#reformatting the initial file to remove tab

SRC=`cat file.txt | expand`

outputs_dir="outputs"

if [ ! -d "$outputs_dir" ];then
  mkdir "$outputs_dir"
else
 echo "$outputs_dir exist"
 #rm "$outputs_dir"/*
fi

#init file outputs array with 2 files first one is in case files is bigger than 5GB

foutputs_array=( "$outputs_dir"/leftover.txt "$outputs_dir"/file1.txt )

#init file size array. Each time a file will be added to an output file, its size will be added here. 
# If its size doesn't fit in an existing file, it will be added to a new file. New file will be added to foutputs_array,...
# If it doesn't fit anywhere, it will go to leftover.

fsize_array=( "0" "0" )

#5GB limit

FLIMIT=5242880

FLAG=0
i=1
array_index=1

fitIn(){

local file_size=$1
local total_size=$2
#echo "summing.." >&2
sum=$(expr $file_size + $total_size)
#echo "sum=" "$sum" >&2
if [[ "$sum" -le "$FLIMIT" ]];then
 echo 0
else
 echo 1
fi
}


while read fsize fname

do
# echo "array_index=" $array_index ${fsize_array[@]} "fsize"$fsize ${fsize_array[$array_index]} 
 check_size=`fitIn $fsize ${fsize_array[$array_index]}`
# echo "check_size" $check_size
 if [ "$fsize" -le "$FLIMIT" -a "$check_size" -eq "0" ];then
 #  echo "In limit"
   FLAG=0  
 elif [ $fsize -le $FLIMIT ];then
 #  echo "In max limit"
   FLAG=0
   while [ $check_size -eq "1" ]
    do
#     echo $array_index $i
     (( array_index++ )) 
     (( i++ )) 
     if [ -z ${fsize_array[$array_index]} ];then 
      fsize_array[$array_index]=0
     fi
     check_size=`fitIn $fsize ${fsize_array[$array_index]}`
    done
#    echo "new position" $array_index
    foutputs_array[$array_index]="$outputs_dir"/file${i}.txt
 else
  echo "$fsize $fname doesn't fit anywhere!"
  FLAG=1
  array_index=0 
 fi 

 if [ $FLAG -eq 0 ];then
  (( fsize_array[$array_index]+=$fsize ))
 fi
 echo "$fsize" "$fname" >> "${foutputs_array[$array_index]}"
 array_index=1
 i=1  
done <<< "$SRC"
2
21.01.2019, 21:50
1 ответ

Предположим, что промежуточный хост разрешает переадресацию портов, вы можете выполнить половину работы с помощью командной строки и закончить графически, как обычно.

sshfs -o ssh_command='ssh -J firstuser@firsthost' finaluser@finalhost:directory localdirectory

Это даст указание sshfs запустить свой бэкэнд ssh (, который сам запускает подсистему sftp в конце )с дополнительной опцией -J, эквивалентной опции конфигурации ProxyJump, которая сама будет прозрачно пересылать SSH подключение к месту назначения.

Это эквивалентно добавлению вместо этого в$HOME/.ssh/config:

Host finalhost
    ProxyJump firstuser@firsthost

и просто запустите sshfs finaluser@finalhost:directory localdirectory, или вы также можете поместить две вышеуказанные строки в файл и использовать опцию -Fдля sshfsс этим файлом.

Теперь ваш каталог localdirectoryможно использовать с Nautilus или любым другим инструментом, с графическим интерфейсом или без (, но, как правило, ограниченным пользователем, работающим sshfs, как обычно ).

Вполне возможно, что наличие этой опции в $HOME/.ssh/configпозволит вашему инструменту с графическим интерфейсом прозрачно работать, как обычно, для монтирования каталога, таким образом, CLI больше не потребуется. Я не мог проверить это.

11
27.01.2020, 22:02

Теги

Похожие вопросы