-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcd-hdfs
30 lines (25 loc) · 816 Bytes
/
cd-hdfs
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
#!/bin/bash
# Auto HDFS mounting | Spencer Tipping
# Licensed under the terms of the MIT source code license
if which hadoop-fuse-dfs > /dev/null; then
cd_on 'h?dfs:[-/][-/][^:/]+:[0-9]+' cd_hdfs_mount cd_hdfs_umount
else
echo 'cd-hdfs: no hadoop-fuse-dfs binary found in $PATH'
fi
function cd_hdfs_mount {
local target=$1
local mountpoint=$2
if [[ "$target" =~ h?dfs:[-/][-/]([^:/]+):([0-9]+)(.*) ]]; then
local namenode=${BASH_REMATCH[1]}
local port=${BASH_REMATCH[2]}
local after_cd=${BASH_REMATCH[3]}
cd_mount "hadoop-fuse-dfs -oprivate" "dfs://$namenode:$port" "$mountpoint"
cd_goto "${after_cd#/}"
else
echo "called cd_hdfs_mount on a non-matching target: $target"
echo "(probably a cd-hdfs bug)"
fi
}
function cd_hdfs_umount {
cd_umount "fusermount -u" "$@"
}