win和Linux之间互传文件

hexo搭建在Linux盒子上,但主要工作在Windows上进行,并且Linux盒子性能不足够带动UI,所以写了一个脚本来实现WindowsLinux的文件互传,前提要配置机器间的ssh密钥对实现无密码登录,Windows上具有Bash环境(msys/Git Bash)(所以就是正常的shell脚本,Linux也可以直接用来传输文件),本篇文章就是使用这个脚本在Windows完成并在Linux生成推送的

这种在Windows的脚本似乎权限不太需要注意,我是直接新建文件就可以用了

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
#!/bin/bash

# remote ip
ri=192.168.1.6
# remote user
ru=root

#remote floder
rf=/root/blog/
# local floder
lf=./
# floder name
fn=source

exec() {
echo "$@"
"$@"
}

pull() {
tf=$(mktemp)
echo Pull $lf/$fn from $rf@$ri:$rf/$fn ...
echo get -r $rf/$fn $lf > $tf
exec sftp -b $tf $ru@$ri
rm $tf
}

push() {
tf=$(mktemp)
echo Push $lf/$fn to $ru@$ri:$rf/$fn ...
echo put -r $lf/$fn $rf > $tf
exec sftp -b $tf $ru@$ri
rm $tf
}

for i in $@; do
case $i in
"pull") pull ;;
"push") push ;;
"ssh") exec ssh $ru@$ri -t -t "cd $rf && bash" ;;
*) ;;
esac
done