简体   繁体   English

Linux crontab 似乎不起作用

[英]Linux crontab doesn't appear to be working

I'm trying to use a cron job on linux to back up my minecraft server every 24 hours.我正在尝试在 linux 上使用 cron 作业每 24 小时备份一次我的 minecraft 服务器。 The crontab looks like this: crontab 看起来像这样:

00 00 * * * bash /home/pi/wgsanarchy/backup.sh

And backup.sh looks like this: backup.sh 看起来像这样:

#!/bin/sh

var=$(date +"%FORMAT_STRING")
now=$(date +"%d_%m_%Y")

tar -zcvf $now-backup.tar.gz /home/pi/wgsanarchy
gupload $now-backup.tar.gz WGSAnarchy
rm /home/pi/$now-backup.tar.gz

(The gupload line pushes the file to my google drive) (gupload 行将文件推送到我的谷歌驱动器)

I've tried to change the time so I can see if it works, but so far I don't think it does.我试图改变时间,所以我可以看看它是否有效,但到目前为止我认为它没有。 Can anyone see any errors?任何人都可以看到任何错误吗?

Thanks!谢谢!

I do not understand why people undervoting instead of helping each other.我不明白为什么人们投票不足而不是互相帮助。

This is a common error in Linux bash script when binaries of tar, gunload and so on are not found at the current directory.当在当前目录中找不到 tar、gunload 等二进制文件时,这是 Linux bash 脚本中的常见错误。 To solve the issue, write the PATH variable at the beginning of the bash script.要解决此问题,请在 bash 脚本的开头写入PATH变量。 Just execute echo $PATH;只需执行echo $PATH; in your terminal/bash and copy the result to make PATH variable like this在您的终端/bash 中并复制结果以制作这样的PATH变量

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM