You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用crontab -e编辑定时任务时出现写入错误,如何解决?

Fixing "error while writing new crontab to /var/spool/cron/#tmp.XXXX..."

This error usually pops up when crontab can't write its temporary file to the /var/spool/cron directory—most often due to permissions, leftover temp files, or disk space issues. Here's how to fix it step by step:

1. Check and Correct Permissions on /var/spool/cron

The /var/spool/cron directory needs specific permissions to let crontab work properly. First, check the current setup:

ls -ld /var/spool/cron

The output should look something like this (varies slightly by distro):

drwx-wx--T 2 root crontab 4096 Aug 10 12:34 /var/spool/cron

If permissions or ownership are off, fix them with these commands:

sudo chown root:crontab /var/spool/cron
sudo chmod 1730 /var/spool/cron

The 1730 permission sets the directory to be writable by root and the crontab group, with the sticky bit enabled to prevent users from deleting each other's crontabs.

2. Clean Up Leftover Temporary Files

Sometimes a failed crontab edit leaves behind a temporary file that blocks subsequent writes. Delete any leftover temp files in the directory:

sudo rm -f /var/spool/cron/#tmp.*

This removes all files starting with #tmp. in the cron spool directory.

3. Check for Disk Space Issues

If the partition containing /var/spool/cron is full, crontab can't write the temp file. Check disk usage with:

df -h /var/spool/cron

If the used percentage hits 100%, free up space by deleting unnecessary files, expanding the partition, or moving data to another drive.

4. Verify User's Crontab Access

Less likely, but worth checking if the above steps don't work:

  • If /etc/cron.allow exists, your username must be listed in it.
  • If /etc/cron.deny exists, your username must NOT be listed in it.

Edit these files with sudo if needed (note: most systems don't have these files by default, so this only applies if they've been manually created).

After trying each step, run crontab -e again to see if the error is resolved.

内容的提问来源于stack exchange,提问作者sampath kv

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:22:26