• 【linux之crontab,启动】


    一、计划任务

    atd

    at命令发布的任务计划
    一次性的任务计划

    at time ctrl+d 提交
    time:
    1.绝对时间:12:00
    2.相对时间:+8
    3.模糊时间:noon midnight teatime
    -l:查看任务列表 相当于atq
    -d #:从任务列表中撤销一个任务计划 相当于atrm
    -c #:显示任务中的命令列表


    例:at 11:13
    at> mkdir /a/b
    at> <EOT> #ctrl+d
    job 4 at 2015-11-21 11:13

    若任务没有成功执行,会收到邮件,用mail命令读取

    at "2:00 2015-12-01"

    atrm 4 撤销4号任务
    at -d 3 撤销3号任务

    cat /etc/sysconfig/atd at的配置文件

    date -s "2015-11-21 10:58:00"
    可在.bashrc_profile写入hwclock -s

    crond

    crontab命令发布的任务计划
    周期性任务计划
    系统的周期性任务
    /etc/crontab

    cat /etc/crontab
    SHELL=/bin/bash
    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    MAILTO=root
    HOME=/
    # For details see man 4 crontabs
    
    # Example of job definition:
    # .---------------- minute (0 - 59)
    # |  .------------- hour (0 - 23)
    # |  |  .---------- day of month (1 - 31)
    # |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
    # |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
    # |  |  |  |  |
    # * *  *  *  *  command to be executed
    (*表示每一分钟) 

    用户个人的周期任务
    crontab
    -e:编辑计划任务 (默认打开vim)
    -l:显示计划任务
    -r:清除计划任务

    * * * * * /bin/date +%F > /dev/pts/0
    * * * * * echo "hello root" /dev/pts/0  #默认每分钟执行一次
    0 2 10 * *            每月十号两点整。修改了时间,周期向上移动一位。确定数字越多,周期越长
    0-10 2 * * * 每天两点整到两点10分,一共执行11次
    0-10/2 2 * * * 每天两点整到两点10分,每两分钟执行一次,也就是隔一分钟执行一次。0分执行,2分执行...

     

    二、启动

    linux系统的启动
    POST-->BIOS-->bootloader-->kernel-->initramfs-->ROOTES-->/sbin/init

    POST加电自检

    主板上存储着一段BIOS程序,规定了硬件设备的启动顺序列表,Bootsequence
    启动顺序设置为硬盘优先启动,为bios设置密码
    harddisk
    CDROM
    removable
    network
    floppy
    MBR

    Bootloader引导启动程序,加载kernel

    init运行级别
    0:关闭系统(不能设置为默认运行级别)
    1:单用户模式 1 S s
    2:多用户模式,但不支持网络文件系统
    3:完全的多用户模式
    4:未被使用的、
    5:图形界面
    6:重新引导

    cat /etc/inittab
     Default runlevel. The runlevels used are:
    #   0 - halt (Do NOT set initdefault to this)
    #   1 - Single user mode
    #   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
    #   3 - Full multiuser mode
    #   4 - unused
    #   5 - X11
    #   6 - reboot (Do NOT set initdefault to this)

    chkconfig --level 3 crond off

    查看当前的运行级别
    runlevel
    N 3

    who -r
    run-level 3 2015-05-11 06:07

    切换运行级别
    init 0

    Bootloader引导启动程序

    windows:NTLDR

    linux:
    LILO:linux loader
    GRUB:grand unified bootloader

    ls /boot/grub/
    device.map ffs_stage1_5 jfs_stage1_5 reiserfs_stage1_5 stage2 xfs_stage1_5
    e2fs_stage1_5 grub.conf menu.lst splash.xpm.gz ufs2_stage1_5
    fat_stage1_5 iso9660_stage1_5 minix_stage1_5 stage1 vstafs_stage1_5

    阶段1:保存在MBR里的446字节
    阶段1.5:保存在grub目录中
    阶段2:磁盘分区

    cat /boot/grub/grub.conf

    default=0 #默认选择第一个标题所对应的内核
    timeout=5 #当用户不做出选择时,默认等待多长时间,单位是秒
    如果是0则表示不需要用户选择,自动启动默认的标题
    如果是-1则表示除非用户选择,否则不会启动系统
    splashimage=(hd0,0)/grub/splash.xpm.gz #启动界面的背景图片yum install imagemagick
    convert source.jpg -resize 640x480! -colors 14 xxx.xpm
    gzip -9 xxx.rpms

    hiddenmenu #隐藏grub引导菜单,除非用户选择显示
    title Red Hat Enterprise Linux (2.6.32-71.el6.i686)
    root (hd0,0)
    kernel /vmlinuz-2.6.32-71.el6.i686 ro root=UUID=0f4c5b88-8b5e-4cdb-8c7a-3f1ef4757703
    rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us nomodeset crashkernel=auto rhgb quiet #内核文件路径及传递给内核的参数
    initrd /initramfs-2.6.32-71.el6.i686.img #假根
    boot分区要是基本分区
    (hd0,0) 在grub看来所有的硬盘都是hd,第一个0表示第一块硬盘,第二个0表示第一个分区

    在引导启动时,如果grub没有配置文件或配置文件已损坏,则需要以下修复步骤
    find (hd#,0)/
    root (hd0,0)
    kernel /vmlinux-2.6.32-71.e16.i686 ro root=/dev/sda3
    initrd /initramfs-2.6.32-71.el6.i686.img
    boot

    如果误删除grub,可以使用下列命令进行命令行级别修复
    grub-install --root-directory=/boot /dev/sda

    从别的主机进行复制
    scp 192.168.100.2:/boot/grub/grub

    开机过程中进入单用户模式。setenforce 0 后可修改root密码

    给grub加密
    grub-md5-crypt >> /boot/grub/grub.conf
    将密码粘贴至第一个titile前,全局生效 password --md5 PASSWD

    kernel在整个启动的过程中,主要功能:
    1.识别设备
    2.加载驱动程序(很可能用到initrd)
    3.以只读方式挂载根文件系统
    4.启动/sbin/init进程

    init
    /etc/inittab
    upstart
    基于事件的触发机制

    systemd

    ls /var/lock/subsys 锁文件

    # chkconfig: 345 95 5
    # description: Runs commands scheduled by the "at" command at the time

    cp 123.sh /etc/init.d/123
    chmod +x /etc/init.d/123
    service 123 start

    chkconfig - updates and queries runlevel information for system services

    SYNOPSIS
    chkconfig [--list] [--type type][name]
    chkconfig --add name
    chkconfig --del name
    chkconfig --override name
    chkconfig [--level levels] [--type type] name <on|off|reset|resetpriorities>
    chkconfig [--level levels] [--type type] name

    chkconfig --add
    chkconfig --del
    chkconfig --list
    chkconfig --level name on|off
    chkconfig name on|off

    chkconfig: 345 95 5
    345:服务需要开启的运行级别,没有被包含的运行级别就是关闭
    95:如果将该服务设置为链接,S开头文件的编号
    5:如果将该服务器设置为链接,K开头文件的编号

    chkconfig --level 3 crond off

  • 相关阅读:
    聊一聊HTML <pre>标签
    [Effective JavaScript 笔记]第20条:使用call方法自定义接收者来调用方法
    数据库的权限管理
    完整性约束
    MYSQL
    Python并发编程之协程
    python并发编程之多线程
    python并发编程之多进程
    进程
    网络编程之socket的运用
  • 原文地址:https://www.cnblogs.com/smallmars/p/8559867.html
Copyright © 2020-2023  润新知