为什么在关机时无法将文件上传到Dropbox?

时间:2018-04-06 08:01:25

标签: autorun systemctl

修复jayant说。

cat upload.sh    
/home/Dropbox-Uploader/dropbox_uploader.sh upload  -f /home/Dropbox-Uploader/.dropbox_uploader   /home/material/*  /
date >>  /home/upload.log

目录素材中的所有文件都可以bash upload.sh上传到我的保管箱中 我想在关机时写一个自动运行服务,将文件上传到dropbox。

vim  /etc/systemd/system/upload.service
[Unit]
Description=upload files into dropbox
Before=network.target shutdown.target  reboot.target

[Service]
ExecStart=/bin/true
ExecStop=/bin/bash  /home/upload.sh 
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target

启用它:

sudo systemctl enable upload.service

重新启动它。

journalctl -u upload

-- Logs begin at Thu 2018-01-18 22:38:54 EST, end at Tue 2018-04-10 06:55:43 EDT. --
Apr 10 06:48:27 localhost systemd[1]: Started upload files into dropbox.
Apr 10 06:48:27 localhost systemd[1]: Starting upload files into dropbox...
Apr 10 06:48:27 localhost bash[111]: which: no shasum in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
Apr 10 06:48:27 localhost bash[111]: > Uploading "/home/material/test.txt" to "/test.txt"...
Apr 10 06:48:27 localhost bash[111]: Error: Couldn't resolve host.
根据{{​​3}}

ln -s /usr/bin/sha1sum /usr/bin/shasum

第二次重启。

journalctl -u dropbox
Apr 10 06:55:04 localhost systemd[1]: Started upload files into dropbox.
Apr 10 06:55:04 localhost systemd[1]: Starting upload files into dropbox...
Apr 10 06:55:04 localhost bash[113]: shasum: invalid option -- 'a'
Apr 10 06:55:04 localhost bash[113]: Try 'shasum --help' for more information.
Apr 10 06:55:04 localhost bash[113]: shasum: invalid option -- 'a'
Apr 10 06:55:04 localhost bash[113]: Try 'shasum --help' for more information.
Apr 10 06:55:04 localhost bash[113]: > Uploading "/home/material/test.txt" to "/test.txt"...
Apr 10 06:55:04 localhost bash[113]: Error: Couldn't resolve host.

正如Raushan所说,新问题出现了,

Uploading    by 4 chunks *** FAILED   dropbox

对于问题Uploading by 4 chunks *** FAILED dropbox,有些材料说如果超过150 MB的文件应该以块的形式上传。

split -b 10m  /home/upload.tar.gz  /home/material/dropbox
ls  /home/material
dropboxaa  dropboxac  dropboxae  dropboxag  ......

它们都不到10米。

journalctl -u upload
Apr 19 01:45:26 localhost systemd[1]: Started upload files into dropbox.
Apr 19 01:45:26 localhost systemd[1]: Starting upload files into dropbox...
Apr 19 01:45:27 localhost bash[401]: > Uploading "/home/material/dropboxaa" to "/dropboxaa"... FAILED
Apr 19 01:45:27 localhost bash[401]: An error occurred requesting /upload
Apr 19 01:45:28 localhost bash[401]: > Uploading "/home/material/dropboxab" to "/dropboxab"... FAILED
Apr 19 01:45:40 localhost bash[401]: Some error occured. Please check the log.
Apr 19 01:45:40 localhost systemd[1]: upload.service: main process exited, code=exited, status=1/FAILURE
Apr 19 01:45:40 localhost systemd[1]: Unit upload.service entered failed state.
Apr 19 01:45:40 localhost systemd[1]: upload.service failed.

为什么> Uploading "/home/material/dropboxaa" to "/dropboxaa"... FAILED

2 个答案:

答案 0 :(得分:0)

脚本的第二条指令不可能在不执行第一条指令的情况下执行。尝试重定向dropbox_uploader.sh的错误输出以查看失败的内容。

假设您正在使用dropbox-uploader,请尝试指定配置文件的确切位置。请参阅README.md

中的作为cron作业运行部分
/home/Dropbox-Uploader/dropbox_uploader.sh -f /path/to/.dropbox_uploader upload /home/material/*  /

答案 1 :(得分:0)

对于无法解决主机问题:

单位配置应具有依赖性 After=network.target代替Before=network.target,因为默认关闭顺序与启动相反

[Unit]
Description=upload files into dropbox
Before=shutdown.target  reboot.target
After=network.target 

[Service]
ExecStart=/bin/true
ExecStop=/bin/bash  /home/upload.sh 
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target  

参考:https://serverfault.com/a/785355

对于 shasum 问题:

我不确定您的操作系统发行版,我使用的是Fedora 25。

在我的情况下,shasum二进制文件来自perl-Digest-SHA包,可以通过基于RedHat的Linux发行版上的命令yum install perl-Digest-SHA安装

参考:https://superuser.com/a/1180163