-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathssh_utils.sh
More file actions
69 lines (56 loc) · 2.33 KB
/
ssh_utils.sh
File metadata and controls
69 lines (56 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
ssh.keys.add() {
ssh-add -l || eval "$(ssh-agent -s)"
for key in ~/.ssh/*; do
[[ -f "$key" && $(head -n1 "$key") =~ "PRIVATE KEY" ]] && ssh-add "$key"
done
}
ssh.pass() {
ssh \
-o PasswordAuthentication=yes \
-o PreferredAuthentications=keyboard-interactive,password \
-o PubkeyAuthentication=no "$@"
return $?
}
ssh.p() {
ssh.pass "$@"
return $?
}
export -f ssh.keys.add
export -f ssh.pass
export -f ssh.p
# ssh.fs.diff() {
# local user="${1:-"$(id -un)"}"
# shift 1 # TODO: add `[if $1 not empty]` condition
# local suffix="${1:-".lan.001"}"
# shift 1 # TODO: add `[if $1 not empty]` condition
# local host="${1:?"Host is required"}"
# shift 1 # TODO: add `[if $1 not empty]` condition
# local ignore="${1:-""}"
# diff \
# <(ssh -o IdentitiesOnly=yes -i "~/.ssh/${user}${suffix}" "${user}@${host}" find -path "${ignore}" -prune ${path1} -printf '"%8s %P\n"') \
# <(find ${path2} -printf '%8s %P\n')
# }
# diff \
# <(ssh -o IdentitiesOnly=yes -i "~/.ssh/$(id -un).lan.001" "$(id -un)@${host}" tree -a --gitignore -I 'bin' -I 'models' -I 'db' -I 'Media' -I 'DL' -I '.cache' -I '.git' -I '0.Mix' -I 'mydb' -I 'myrepo' -I '.pnpm-store' -I '.Trash-1000' -I 'lost+found' -I '1.vm.d' -I 'linux-roots' -F --noreport --dirsfirst -i -f -L 4 -d /$pathtodata/ | sed 's|/$pathtodata||g') \
# <(tree -a --gitignore -I 'bin' -I 'models' -I 'db' -I 'Media' -I 'DL' -I '.cache' -I '.git' -I '0.Mix' -I 'mydb' -I 'myrepo' -I '.pnpm-store' -I '.Trash-1000' -I 'lost+found' -I '1.vm.d' -I 'linux-roots' -F --noreport --dirsfirst -i -f -L 4 -d /$pathtodata/ | sed 's|/$pathtodata||g')
# user_host=$1
# remote_dir=$2
# local_dir=$3
# shift 3
# exclude_dirs=("$@")
# # Build exclude arguments for find
# exclude_args_remote=()
# exclude_args_local=()
# for dir in "${exclude_dirs[@]}"; do
# exclude_args_remote+=( -path "$remote_dir/$dir" -prune -o )
# exclude_args_local+=( -path "$local_dir/$dir" -prune -o )
# done
# # Remote find command
# remote_find_cmd="find $remote_dir ${exclude_args_remote[*]} -print"
# # Local find command
# local_find_cmd="find $local_dir ${exclude_args_local[*]} -print"
# # Compare outputs
# diff <(ssh -o IdentitiesOnly=yes $user_host "$remote_find_cmd") <(eval "$local_find_cmd")
# Compress a list of files on the remote
# ssh user@remote "cd /path/to/directory && tar -cvf allfiles.tar -T -" < mylist.txt