Linux Ubuntu crontab 添加错误 提示:no crontab for root - using an empty one 888

资料

错误提示:
no crontab for root - using an empty one 888

原因剖析:
第一次使用crontab -e 命令时会让我们选择编辑器,很多人会不小心选择默认的nano(不好用),或则提示no crontab for root - using an empty one 888;这时候我们要重新选择编辑器

解决方法:

  • 使用root用户登陆系统:sudo root / su - root
  • 输入命令:select-editor
  • 输入数字:3 (选择vi编辑器 回车) 选择/usr/bin/vim.basic 这里在不同的机器上序号也不一定一致。如:![[Pasted image 20220302142550.png]]
  • 重新输入crontab -e就可以进行编辑定时任务了

下面是添加定时任务案例
输入命令:crontab -e

实操

  1. 系统 —— Ubuntu
  2. 用户:普通用户
  3. 环境:未配置root账户密码
  4. 问题记录:
    1. 首先,编写完成脚本之后,使用crontab -l 查看定时任务。此时该用户下无任务
    2. 然后使用 crontab -e 编写任务,出现让选择界面,随便点选一个之后不能使用。这里我选择的是4
    ftp123@ubuntutest-virtual-machine:~$ crontab -e
    
    Select an editor.  To change later, run 'select-editor'.
    1. /bin/nano        <---- easiest
    2. /usr/bin/vim.basic
    3. /usr/bin/vim.tiny
    4. /bin/ed
    
    Choose 1-4 [1]: 4
    
    1. 这里在使用root用户按照如资料操作后并不能解决问题
    2. 最后测试明白,需要在出现问题的账户下使用select-editor命令来更改错误的模式。
    3. 另外,ubuntu系统和redhat系统不同的地方在于,Ubuntu可以不再预先设置root账户的密码,使用具有sudo 权限的用户使用 sudo passwd root 可以直接设置root账户密码。
    4. 附部分错误调试代码
ftp123@ubuntutest-virtual-machine:/var/spool/cron$ sudo vi /etc/crontab 
[sudo] password for ftp123: 
ftp123 is not in the sudoers file.  This incident will be reported.
ftp123@ubuntutest-virtual-machine:/var/spool/cron$ sudo vim /etc/crontab 
[sudo] password for ftp123: 
ftp123 is not in the sudoers file.  This incident will be reported.
ftp123@ubuntutest-virtual-machine:/var/spool/cron$ crontab -l
no crontab for ftp123
ftp123@ubuntutest-virtual-machine:/var/spool/cron$ crontab -e
no crontab for ftp123 - using an empty one
888
1
# Edit this file to introduce tasks to be run by cron.
3
# Each task to run has to be defined through a single line
2
# 

# Each task to run has to be defined through a single line
15 * * * * ftp123 /home/ftp123/bin/clear_file.sh
?

# indicating with different fields when the task will be run
^C
?
^C
?
^Z
[4]+  Stopped                 crontab -e
ftp123@ubuntutest-virtual-machine:/var/spool/cron$ cd ~
ftp123@ubuntutest-virtual-machine:~$ nano 1.sh
Use "fg" to return to nano.

[5]+  Stopped                 nano 1.sh
ftp123@ubuntutest-virtual-machine:~$ 

猜你喜欢

转载自blog.csdn.net/qq_29111047/article/details/131884183
今日推荐