AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题

问题[crontab](ubuntu)

Martin Hope
pbreitenbach
Asked: 2011-04-02 15:40:52 +0800 CST

Cron 用户 root 或 www-data?

  • 2

我在 10.04 上运行一个网站,但不确定如何设置我的 crontab。我应该在 root 下还是在 www-data 等用户下创建它?Python、Postgres、Nginx。

crontab
  • 1 个回答
  • 4089 Views
Martin Hope
Bakhtiyor
Asked: 2011-02-28 17:30:57 +0800 CST

Ubuntu启动后如何在后台自动访问网站?

  • 0

我想知道如何在 Ubuntu 加载时在后台自动访问网站。据我所知w3m是从控制台访问网站。这就是为什么我在crontab -e.

@reboot w3m http://example.com/ > test_file

将网站内容写入a的test_file原因只是为了知道该命令是否已执行。不幸的是,它并没有在每次 Ubuntu 加载时执行。但是在它之后的下一个命令看起来像这样:@reboot date >> reboot_file每次都在执行。

我的命令有什么问题?当我在控制台中执行它时,它会输出example.cominto的内容test_file。

还有其他选择吗?

crontab
  • 2 个回答
  • 1437 Views
Martin Hope
Bakhtiyor
Asked: 2011-02-12 16:09:51 +0800 CST

如何解释这个 crontab 命令?

  • 1

我知道如果我在crontab -e以下命令 中编写,01 04 * * * somecommand那么它将somecommand在每个月的每一天凌晨 4:01 运行。

如果我写了会发生什么* * * * * somecommand?它会somecommand每分钟运行一次吗?这种语法也可以吗?

并且可以使用这里@reboot解释的特殊字符串,如,@daily等。如果我写命令,将在一天中的什么时间执行?somecommand@daily somecommand

crontab
  • 2 个回答
  • 6618 Views
Martin Hope
aneuryzm
Asked: 2011-01-09 05:31:48 +0800 CST

rsnapshot.conf 中的“备份间隔”?

  • 11

关于rsnapshot的一个简单问题。

为了执行每日备份,我将在我的 Ubuntu 中向 cron 添加行。

那么,为什么我在 rsnapshot.conf 中也有这些行?

#########################################
#           BACKUP INTERVALS            #
# Must be unique and in ascending order #
# i.e. hourly, daily, weekly, etc.      #
#########################################

interval        hourly  6
interval        daily   7
interval        weekly  4
#interval       monthly 3

如果我使用 cron,我应该禁用它们吗?谢谢

附言。我刚刚意识到在 crontab 中我仍然有“每小时”和“每天”。然后我应该只取消注释我在 crontab 中使用的那个吗?如果已经在 cron 中指定了每小时,那么指定每小时有什么意义?我有点困惑。

# crontab -e
0 */4 * * * /usr/local/bin/rsnapshot hourly
30 23 * * * /usr/local/bin/rsnapshot daily
crontab
  • 4 个回答
  • 15101 Views
Martin Hope
aneuryzm
Asked: 2011-01-04 03:48:01 +0800 CST

如何自动化mysql备份?

  • 2

我想用 cron 自动备份我的数据库和文件。我应该将以下行添加到 crontab 吗?

mysqldump -u root -pPASSWORD database_name | gzip > /home/backup/database_`date +\%m-\%d-\%Y`.sql.gz

svn commit -m "Committing the working copy containing the database dump"

1)首先,这是一个好方法吗?
2)不清楚如何用svn指定存储库和工作副本。
3)我怎样才能只在mysqldump完成而不是之前运行svn?避免冲突

还有其他提示吗?谢谢

cron-jobs cron crontab svn
  • 1 个回答
  • 3543 Views
Martin Hope
Jon
Asked: 2010-11-18 06:27:39 +0800 CST

如何使用 crontab、.netrc 和 git push?

  • 3

我正在将各种服务器的备份自动化到一个中心点,然后将这些配置更改推送到一个 git repo 中,这样我就可以随着时间的推移跟踪任何更改。其余脚本运行良好,我可以通过网络将文件复制/同步到中心点。最后一个脚本是获取要放入/更新存储库的配置文件。脚本如下:

#!/bin/bash
clear

SERVERNAME="betty"
SCRIPTDIR="/home/jon"
GITROOT="/tmp/git"
TEMPROOT="/tmp/backups"
BACKUPROOTDIR="/mnt/backups"

echo "  - running as user: $UID"

echo "backingup git config on $SERVERNAME"
echo ""

# check to see if root backup folder exists, otherwise create it.
if [ -d $GITROOT ]; then
    rm -rf $GITROOT
fi
mkdir $GITROOT

cd $GITROOT

echo "  - testing if home is where I think it should be!"
echo $HOME
echo "  - testing if it can see netrc"
tail $HOME/.netrc


git clone http://192.168.10.97:8000/repositories/HOH-config-backups.git
cd HOH-config-backups

echo "  - copy Configuration Folders across"
cp -r $BACKUPROOTDIR/Configuration/* $GITROOT/HOH-config-backups/
cp -r $BACKUPROOTDIR/scripts $GITROOT/HOH-config-backups/

git add .
git commit -a -m "committing any new configuration changes!"
git push origin master

echo ""
echo "Git repo updated"

echo ""
echo "  - backing up this script"
FIREWIGSCRIPTLOC="$BACKUPROOTDIR/scripts/$SERVERNAME"

if [ ! -d $FIREWIGSCRIPTLOC ]; then
    mkdir $FIREWIGSCRIPTLOC
fi

cp /home/jon/gitConfig.sh  $FIREWIGSCRIPTLOC

git repo 位于使用 Apache 和 HTTP-backend.exe(智能 HTTP 协议)的网络中的另一台机器上。如果我以“jon”身份运行这个脚本,它就可以工作。如果我在 crontab 中运行它,它会失败。git 使用 /home/jon/.netrc 文件进行身份验证:

machine 192.168.10.97
login gitconfig
password 1234579

来自 crontab 的日志是:

TERM environment variable not set.
  - running as user: 1000
backingup git config on betty

  - testing if home is where I think it should be!
/home/jon
  - testing if it can see netrc
machine 192.168.10.97
login gitconfig
password 1234579
got 08de5bc2b27b4940d9412256e76d5e3c3d9dbcdd
walk 08de5bc2b27b4940d9412256e76d5e3c3d9dbcdd
got be880f2d306778a538d592e7a02eb19f416612f7
got bd387e8def9f77aafa798bf53e80d949aba443e8
got 1bc1a59e12775841d4c59d77c63b8a73823138c2
walk bd387e8def9f77aafa798bf53e80d949aba443e8
Getting alternates list for http://192.168.10.97:8000/repositories/HOH-config-backups.git
got 030512237bca72faf211e0e8ec2906164eac34f6
got 9bc2f575240bc1f61ff7d69777ce1a165d06b184
got b8400f7f01429104a9d4786a6bb1a16d293e37c1
got 2403b5bf611010e0b401f776f0e23b09ce744838
got 1a27944c48269ef3608a8f2466e43402d06faac0
got b686f45b7d57af4fa8ca0d528bb85216d6247e19
Getting pack list for http://192.168.10.97:8000/repositories/HOH-config-backups.git
Getting index for pack ae881957c0f0e8c22eb6cc889a22ef78eb4ce6ff
Getting pack ae881957c0f0e8c22eb6cc889a22ef78eb4ce6ff
 which contains ff84d6d48e9326066438d167a10251218d612b3d
walk b686f45b7d57af4fa8ca0d528bb85216d6247e19
got 364e30daec17814073e668f490bb84af891fe1f7
got 23f6497e7f9b80e0d90adad73bd0407a0e5ac6ce
got 9e77c47574b5e23ea669afe0c23ab235e4917ee1
got 6654e0d328a216b3783e98c47206cb2d01b3353d
got 28821ffd437d2689ffb82c6e4b9c3f5372c95c4b
got 8c384a24f645389e4d4b08013c79e9e73a658342
got d203be0123736ee025ce20c081f1489098648dfc
got 1852603bf7709e71417d8ccec02390279d533642
got fb753a26b20b04694419fce8ecdaa8dbec105cf1
got 736028997cd84dd1c135f57e9d246674b9cd0b9d
got 7af836249e20096d0476a548d5be702a071cdd4b
got 240dc39d9db50df63073fc7927b2d002dfa0f54c
got 93abd36e3935a01011eb753b635a1a0e984bf31e
got c6269e28fecf4d8d0d98b9358aecb3acff02df44
got b0aa29432f73e64032682a351d436c24b14078ab
walk 240dc39d9db50df63073fc7927b2d002dfa0f54c
got 58fb66d9f35f8a5e32ff4683309c5f0c2a3a03c5
got 0da2def4de0565483cdbe6b87418ee2beb122e58
got 0f6a86c6f87ed52ad2ed01e5c6edd661d364930c
got 437a93d27b5bb89c739a0564a34a616e832c3ebe
got fe0385abe5c0acd8462268dac330bae00e934f1b
got 24259f8f5c5c9ee974a75fe3d1e07c02e3e20fe9
got d29f624bf1a5eceedaa86c10fee35f62747c7d04
got 0154e4c987132585ea7a92b77d02dba285512d6b

got eda8bf526567c25ee70addb2ad3c3c6aa57eac77
got 9f3d9d7262d66f9fa4f6a13b7c86199953f4bc4e
got 8e20881e19667aa22245d0598646991067455a4d
got abb1123145689b35eb19519952c71253ee45fa98
got dfeff593c79b4156ce2ce1adf043d0e80356488c
got e20c5b48b1d360e0bcf34189e3f3d2bbf23e92cc
got b13eb81cc274780322ecf786372320343926bec9
walk 8de83868b3fac748b0a55eba16c8f668ec852abb
got b5961421bbc42afe7a07cc1c8b615aba26ba74d7
got 2650ba819019df4193b482733e29ca79b29f3f2c
got b3111e1be8103e91803a97a817ed81f28025aca1
got b060be934d709684f5eb5dad3c03932a3589e864
got cf70d2043f081d7a4438e9d5a290a9f986c84060
got 80bf0f1cc836feab86d6935bb7968d8555a8d531
got da318d167920e34bc6573e4fc236249ccbbee316
got d82ac853d387b760149599e6e1ab96403f6ec672
got 0005f691d1f46550fdb4e56025f52e30a5b18cc2
Initialized empty Git repository in /tmp/git/HOH-config-backups/.git/
  - copy Configuration Folders across
Created commit 424df2f: committing any new configuration changes!
 3 files changed, 55 insertions(+), 1 deletions(-)
 create mode 100755 scripts/betty/gitConfig.sh
error: Cannot access URL http://192.168.10.97:8000/repositories/HOH-config-backups.git/, return code 22
error: failed to push some refs to 'http://192.168.10.97:8000/repositories/HOH-config-backups.git'

    Git repo updated

      - backing up this script
    cp: cannot create regular file `/mnt/backups/scripts/betty/gitConfig.sh': Permission denied

我的 crontab 是:

# m h  dom mon dow   command
04 * * * * /home/jon/gitConfig.sh > /tmp/gitconfig.log 2>&1

我通过以下方式打开它:

$crontab -e

即不是根。

了解用户标识:

jon@betty:~$ id
uid=1000(jon) gid=1000(jon)  groups=4(adm),20(dialout),24(cdrom),46(plugdev),109(sambashare),114(lpadmin),115(admin),1000(jon)

这是我的 $HOME/.gitconfig 文件:

[user]
    name = Jon Hawkins
    email = [email protected]
crontab git
  • 1 个回答
  • 2498 Views
Martin Hope
Wolfy
Asked: 2010-10-23 04:59:39 +0800 CST

Cron 邮件通知

  • 2

我想为我的一项任务禁用 crontab 邮件通知...

我每分钟运行一次这个任务,这意味着每天有 1440 封邮件:S

有人可以告诉我这是否可行,我该怎么做?

notification mail crontab
  • 1 个回答
  • 858 Views
Martin Hope
Switchkick
Asked: 2010-10-20 23:55:08 +0800 CST

Cron.hourly 不会运行

  • 68

/etc/cron.hourly好的,所以我已经制作了我的脚本,我将它放入chmod 777文件中,但它不会(自动)运行。如果我手动运行它,它工作正常。我还需要做其他事情吗?

command-line cron-jobs cron crontab
  • 5 个回答
  • 56338 Views
Martin Hope
Dima
Asked: 2010-08-30 16:54:27 +0800 CST

网络启动时如何运行cron作业?

  • 8

我有一些每天运行的 anacron 作业。这些脚本更新本地 bzr 和 git 存储库。自然,这些脚本需要有效的网络连接。我在笔记本电脑上,经常有线和无线互联网速度不够快。这会导致我的 cron 作业在提取存储库时超时 =(

所以:

如何在运行特定的 cron 作业之前确保互联网已启动?或者如果没有网络,如何使工作失败,以便 anacron 稍后再次重试?

cron-jobs cron crontab
  • 9 个回答
  • 20354 Views
Martin Hope
grokus
Asked: 2010-08-26 11:28:44 +0800 CST

我的 cron.hourly 配置有什么问题?

  • 6

每小时我都会收到一封带有此类错误的电子邮件,

Subject: Cron <root@supa> root    cd / && run-parts --report /etc/cron.hourly

/bin/sh: root: not found

/etc/crontab 的内容如下,我删除用户“root”或不删除(第 6 列),我得到同样的错误。

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
11 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

我的 cron.hourly 目录中有两个文件,

$ ll /etc/cron.hourly/
total 0
lrwxrwxrwx 1 root root 25 2009-10-29 09:24 ntpsync -> /home/<user>/bin/ntpsync
lrwxrwxrwx 1 root root 28 2009-10-23 10:33 foo -> /home/<user>/bin/foo

第一个脚本如下所示,

$ cat ~/bin/ntpsync
#!/usr/bin/env bash
echo "user: $USER"
if [[ "$USER" == "root" ]] ; then
    ntpdate ntp.ubuntu.com
else
    sudo ntpdate ntp.ubuntu.com
fi

即使我删除了 /etc/cron.hourly/ 目录中的两个脚本,我仍然每小时都会收到相同的错误电子邮件。我尝试重新启动 cron,但仍然收到相同的错误电子邮件。我的下一个想法是重新启动,但我会避免这种情况。

$ sudo /etc/init.d/cron restart

我的 Ubuntu 版本如下,

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=8.04
DISTRIB_CODENAME=hardy
DISTRIB_DESCRIPTION="Ubuntu 8.04.1"

更新:我之前从 /etc/crontab 文件中删除了第 6 列“root”,因为当我在线搜索时,有人提到可以解决问题。现在我认为问题在于我在搞乱系统 crontab 配置而不是 root 的配置。

$ sudo crontab -l
# m h  dom mon dow   command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
cron-jobs crontab
  • 5 个回答
  • 14037 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve