ydcmd.py put not working from shell script
Closed this issue · 1 comments
Weird problem. When I upload manually, ydcmd.py works fine. But if I use the following command in a shell script, it doesn't work:
if ! $ydroot ; then # upload to subfolder
if ! $(ydcmd.py --timeout=30 --token=$yadisk_token put "$filepath" "/$yadisk_path/$filename" 2>/dev/null) ; then
_beep
echo "Upload error!" >&2
url=""
else
url=$(ydcmd.py --timeout=30 --token=$yadisk_token share "/$yadisk_path/$filename" 2>/dev/null | awk -F"\ \-\>\ " '{print substr($0, index($0,$2))}')
fi
else # upload to root
Other commands work fine from the shell script, e.g. ydcmd.py stat
, ydcmd.py info
etc.
Can't see what the problem with ydcmd.py
could be.
PS (edit): tried using a copy of ydcmd.py in my path, not just a symlink. Tried running plain ydcmd.py without the if ! $(ydcmd.py ... ) ; then
part. Tried putting the double quotes only around the variables, not including the slashes /
… nothing works.
Found the problem, which is a mixture of an error in the script and an error at Yandex Disk as compared to pCloud.
My variable $yadisk_path
already had a leading slash from before in the script, i.e. /Uploads
, and the ydcmd.py put
command then actually turned it into //Uploads/$filename
. Debug output suggests that Yandex Disk only found the directory /Uploads
in root, but not //Uploads
, so it was trying to create the directory //Uploads
first, killing one leading slash, as that seems to be their procedure, but being unable to create a directory with a filename that has a leading slash.
pCloud removes all leading slashes, which is why you can actually specify an erroneous path of //Uploads
in root: pCloud knows how to handle it, Yandex Disk doesn't.
Seems to be working now, so there's no need for you to become active, but maybe you might want to think about adding a little routine to ydcmd.py to clean up any misnomers that get passed along as arguments. (But it's really up to the users to make sure it works.) But yes, Yandex Disk doesn't seem to behave too intelligently here. ;)