-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.sh
More file actions
75 lines (58 loc) · 1.15 KB
/
2.sh
File metadata and controls
75 lines (58 loc) · 1.15 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
70
71
72
73
74
75
#!/bin/bash
if [ $# != 2 ]; then
echo "exactly two parameters required!"
exit 0
fi
if [ "$1" == "" ]; then
echo "keyword not valid!"
exit 0
fi
echo "local result:"
if ! [ -d $2 ]; then
echo "directory not valid!"
exit 0
fi
kw=$1
dir=$2
cur_dir=$dir
original_dir_flag=true
file_list=`ls -R $dir | grep -v '^$' | sed 's/://'`
for file_name in $file_list
do
temp_row=`echo $file_name`
if [[ $temp_row =~ ./ ]] && $original_dir_flag; then
original_dir_flag=false;
fi
if [ -d "$temp_row" ] && ! $original_dir_flag; then
cur_dir=$temp_row
else
if [[ $temp_row =~ $kw ]]; then
echo "local:$cur_dir/$temp_row :*$kw"
fi
fi
done
echo "remote result:"
ssh username@remotehost << EOF
if ! [ -d $2 ]; then
echo "directory not valid!"
exit 0
fi
cur_dir=$dir
original_dir_flag=true
file_list=`ls -R $dir | grep -v '^$' | sed 's/://'`
for file_name in $file_list
do
temp_row=`echo $file_name`
if [[ $temp_row =~ ./ ]] && $original_dir_flag; then
original_dir_flag=false;
fi
if [ -d "$temp_row" ] && ! $original_dir_flag; then
cur_dir=$temp_row
else
if [[ $temp_row =~ $kw ]]; then
echo "local:$cur_dir/$temp_row :*$kw"
fi
fi
done
exit
EOF