SuperNG6 / docker-aria2

Docker Aria2的最佳实践
https://hub.docker.com/r/superng6/aria2
418 stars 45 forks source link

脚本有问题 #13

Closed zlx42 closed 4 years ago

zlx42 commented 4 years ago

我在群晖里装的,脚本判断有问题,好像没把path里的扩展名去掉,导致出错 path=${path%%.*}之类的?

SuperNG6 commented 4 years ago

我觉得没有问题吧,如果无法执行,大概是因为权限问题,readme里的文档有写

#!/bin/bash

downloadpath='/downloads'

filepath=$3
rdp=${filepath#${downloadpath}/}
path=${downloadpath}/${rdp%%/*}

if [ $2 -eq 0 ]
    then
        exit 0
elif [ "$path" = "$filepath" ] && [ $2 -eq 1 ]
    then
    [ -e "$filepath".aria2 ] && rm -vf "$filepath".aria2
    exit 0
elif [ "$path" != "$filepath" ] && [ $2 -gt 1 ]
    then
    [ -e "$path".aria2 ] && rm -vf "$path".aria2
    exit 0
elif [ "$path" != "$filepath" ] && [ $2 -eq 1 ]
    then
    [ -e "$filepath".aria2 ] && rm -vf "$filepath".aria2
    exit 0
fi
zlx42 commented 4 years ago

新版本好像还是不行,我改成这样就可以

#!/bin/bash

downloadpath='/downloads'
filepath=$3
rdp=${filepath#${downloadpath}/}
path=${downloadpath}/${rdp%%/*}

if [ $2 -eq 0 ]
    then
        exit 0
elif [ "$path" = "$filepath" ] && [ $2 -eq 1 ]
    then
    path2=${path%.*}
    [ -e "$path2".aria2 ] && rm -f "$path2".aria2 
    exit 0
elif [ "$path" != "$filepath" ] && [ $2 -gt 1 ]
    then
    path3=${path%.*}
    [ -e "$path3".aria2 ] && rm -f "$path3".aria2
    exit 0
elif [ "$path" != "$filepath" ] && [ $2 -eq 1 ]
    then
    path4=${path%.*}
    [ -e "$path4".aria2 ] && rm -f "$path4".aria2
    exit 0
fi
SuperNG6 commented 4 years ago

今天抽时间研究了一下aria2的参数传递,更新了删除文件的脚本,经过测试删除功能正常运行,删除功能已完善

zlx42 commented 4 years ago

我在群晖里面还是不行,$3是带有扩展名的~你的这个删除时有扩展名就出错

SuperNG6 commented 4 years ago

这个脚本是这样的,它做了几个判断,在aria2里,如果下载的一个文件夹里带多个文件,那么aria2文件会在上一级目录,我在shell写了截取目录的命令,所以可以正确截取目录,

dirpath=${filepath%/*}
elif [ "$path" != "$filepath" ] && [ $2 -gt 1 ]
then
[ -e "$dirpath".aria2 ] && rm -vrf "$dirpath".aria2 "$dirpath"
exit 0 
SuperNG6 commented 4 years ago

我的建议是你删除容器,重新建一个,脚本估计是因为你修改过所以没被替换 你可以进容器 cat /aria2/script/delete.sh 看一下是否是新的脚本

zlx42 commented 4 years ago

容器更新过了,我容器看过了,是最新的脚本。 后来不行,我自定义的脚本也换成你的最新版了。结果还是不行

我用echo [$(date)] $filepath "
" >> /config/_log.html输出记录的是 /downloads/abcd/abcd.mp4之类的,

[Wed Feb 26 19:19:33 CST 2020] m1 , /downloads/trackers_all.txt
[Wed Feb 26 20:59:41 CST 2020] m3 , /downloads/abcd.mp4

但是.aria2文件是/downloads/abcd.aria2 感觉应该是你的filepath直接用的$3,是带扩展名的,你的脚本目前只有dirpath是正确的,其他的只要用[ -e "$filepath".aria2 ] && rm -vf "$filepath".aria2都会变成/downloads/abcd/abcd.mp4.aria2这样的就删除失败了。。。。

!/bin/bash

downloadpath='/downloads'

filepath=$3 rdp=${filepath#${downloadpath}/} path=${downloadpath}/${rdp%%/} dirpath=${filepath%/}

if [ $2 -eq 0 ] then exit 0 elif [ "$path" = "$filepath" ] && [ $2 -eq 1 ] then [ -e "$filepath".aria2 ] && rm -vf "$filepath".aria2 echo [$(date)] m1 , $filepath "
" >> /config/_log.html
exit 0 elif [ "$path" != "$filepath" ] && [ $2 -gt 1 ] then [ -e "$dirpath".aria2 ] && rm -vf "$dirpath".aria2 echo [$(date)] m2 , $dirpath "
" >> /config/_log.html
exit 0 elif [ "$path" != "$filepath" ] && [ $2 -eq 1 ] then [ -e "$dirpath".aria2 ] && rm -vf "$filepath".aria2 echo [$(date)] m1 ,$dirpath "
" >> /config/_log.html exit 0

SuperNG6 commented 4 years ago

因为是有文件数量的判断,大于二的文件数是有文件夹的,所以删除的是dirpath,一个文件直接删除filepath就可以

zlx42 notifications@github.com于2020年2月26日 周三下午10:07写道:

容器更新过了,我容器看过了,是最新的脚本。

我用echo [$(date)] $filepath " " >> /config/_log.html输出记录的是 /downloads/abcd/abcd.mp4之类的,

[Wed Feb 26 19:19:33 CST 2020] m1 , /downloads/trackers_all.txt

[Wed Feb 26 20:59:41 CST 2020] m3 , /downloads/abcd.mp4

但是.aria2文件是/downloads/abcd.aria2 感觉应该是你的filepath直接用的$3,是带扩展名的,你的脚本目前只有dirpath是正确的,其他的只要用[ -e "$filepath".aria2 ] && rm -vf "$filepath".aria2都会变成/downloads/abcd/abcd.mp4.aria2这样的就删除失败了。。。。

!/bin/bash

downloadpath='/downloads'

filepath=$3 rdp=${filepath#${downloadpath}/} path=${downloadpath}/${rdp%%/ } dirpath=${filepath%/}

if [ $2 -eq 0 ] then exit 0 elif [ "$path" = "$filepath" ] && [ $2 -eq 1 ] then [ -e "$filepath".aria2 ] && rm -vf "$filepath".aria2

echo [$(date)] m1 , $filepath "" >> /config/_log.html exit 0 elif [ "$path" != "$filepath" ] && [ $2 -gt 1 ] then [ -e "$dirpath".aria2 ] && rm -vf "$dirpath".aria2

echo [$(date)] m2 , $dirpath "" >> /config/_log.html exit 0 elif [ "$path" != "$filepath" ] && [ $2 -eq 1 ] then [ -e "$dirpath".aria2 ] && rm -vf "$filepath".aria2 echo [$(date)] m1 ,$dirpath " " >> /config/_log.html exit 0

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/SuperNG6/docker-aria2/issues/13?email_source=notifications&email_token=AG2C73SPYQT5ECPNP3RYMPTREZZSJA5CNFSM4JXRDLD2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENALMBQ#issuecomment-591443462, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG2C73W5XUPFZOKAOCI6PO3REZZSJANCNFSM4JXRDLDQ .

zlx42 commented 4 years ago

都说了按输出的记录显示filepath内容使用扩展名的,你用dirpath之类的都是对的,但是用filepath输出的都带扩展名。

[Wed Feb 26 19:19:33 CST 2020] m1 , /downloads/trackers_all.txt

"$filepath" 的内容是 /downloads/abcd.mp4 ,所以命令输出就会变成/downloads/abcd.mp4.aria2 是不是DSM6.22这个群晖系统有问题??