OneDrive上传文件脚本+Aria2自动上传
Github地址:https://github.com/iiiiiii1/OneDrive
1、安装脚本
安装curl,用于访问API:
#Ubuntu和Debian系统 apt-get install -y curl #Centos系统 yum install curl -y
运行命令安装脚本:
#为了方便小白,本脚本内置萌咖大佬永久有效的应用参数,可以直接使用,如果你不放心可以自己获取参数,不过可能会遇到很多坑,建议直接使用脚本默认的参数 wget --no-check-certificate -q -O /tmp/OneDrive.sh "https://raw.githubusercontent.com/iiiiiii1/OneDrive/master/OneDrive.sh" && chmod +x /tmp/OneDrive.sh && bash /tmp/OneDrive.sh
直接使用默认就好,用自己获取的会报错。
2、运行账号认证程序
运行命令onedrive -a,将返回的网址复制到浏览器打开(此处需要梯子),再登陆你的OneDrive for Business账号,登陆成功后复制地址栏中的地址,并提取code的字段(就是code=后面至&前面),粘贴到SSH客户端里,敲回车键即可。

如果返回以下字段:It seems like we have a refresh token, so we are ready to go,那就恭喜你,设置成功!
使用
1、使用命令
onedrive --help
Usage: onedrive [OPTIONS] file1
onedrive-d floder
Options:
-d, --debug Enable debug mode
-a, --authorize Run authorization process
-f, --folder Upload files into this remote folder
-u, --update Upload files into this remote folder after aria2 download complete
-c, --creat Creat remote folder.
Directory names are separated with a slash,
echo e.g.rootFolder/subFolder
Do NOT use a trailing slash!
-h, --help Show this help
-r, --rename Rename the files during upload
For each file you specify you MUST also specify
the remote filename as the subsequent parameter
Be especially careful with globbing!
-s, --silent Silent mode for use in crontab scripts.
Return only exit code.
-ls,--list Show the itmes in this directory.
-l, --link Show the file share link.2、Aria2自动上传脚本
#!/bin/bash
num="$2"
path="$3"
downloadpath='/home' #下载目录
if [ $num -eq 0 ]
then
exit 0
fi
function getdir(){
IFS=$'\n';for file in `ls "$1"`
do
if [ -d "$1/$file" ]
then
getdir "$1/$file"
else
if [ "${1%/*}" = "$downloadpath" ] && [ $num -eq 1 ]
then
/usr/local/etc/OneDrive/onedrive "$1"
elif [ $num -eq 1 ]
then
/usr/local/etc/OneDrive/onedrive "$1/$file"
else
/usr/local/etc/OneDrive/onedrive -u "$downloadpath" "$1/$file"
fi
fi
done
}
while true; do
filepath=$path
path=${path%/*};
if [ "$path" = "$downloadpath" ]
then
getdir "$filepath"
if [ -d $filepath ]
then
rm -r "$filepath"
else
rm "$filepath"
fi
echo 3 > /proc/sys/vm/drop_caches
swapoff -a && swapon -a
exit 0
fi
done新建脚本文件upload.sh,并复制上面代码
授权chmod +x upload.sh,然后再到Aria2配置文件中加上一行on-download-complete=/root/upload.sh即可,后面为脚本的路径。
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
评论已关闭