尚观第十天学习计划任务网络

来源:互联网 发布:js设置select值 编辑:程序博客网 时间:2024/04/29 01:45
网络:
[root@station230 ~]# ifconfig eth0:0 192.168.100.254/25
[root@station230 ~]# ifconfig eth0 down
[root@station230 ~]# ifconfig eth0 up
[root@station230 ~]# ifdown eth0
[root@station230 ~]# ifup eth0

ip
设置主机名:
[root@station230 ~]# vim /etc/sysconfig/network

DEVICE=eth0
BOOTPROTO=static
HWADDR=40:16:9f:f3:53:b4
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.1.253

帮助文件:
/usr/share/doc/initscripts-8.45.30/sysconfig.txt

ping命令:
[root@station230 ~]# ping -s 1000  -c 1 192.168.100.253

查看对方mac地址:
[root@station230 ~]# arp -a
[root@station230 ~]# arping 192.168.100.51
ARPING 192.168.100.51 from 192.168.100.253 eth0
Unicast reply from 192.168.100.51 [00:E0:4C:14:F4:A5]  0.633ms

绑定mac地址
[root@station230 ~]# arp -s 192.168.100.51 00:E0:4C:14:F4:A5
删除:
[root@station230 ~]# arp -d 192.168.100.51
永久绑定
[root@station230 ~]# vim /etc/ethers
00:E0:4C:14:F4:A5  192.168.100.51

[root@station230 ~]# route -n
[root@station230 ~]# route add default gw 192.168.100.1
[root@station230 ~]# route add -net 192.168.254.0/24 gw 192.168.100.1

[root@station230 ~]# route add -host 192.168.200.100 gw 192.168.100.1


DHCP:动态主机配置协议
[root@station230 Desktop]# rpm -qa | grep dhc
dhcp-3.0.5-23.el5
dhcp-devel-3.0.5-23.el5
dhclient-3.0.5-23.el5
[root@station230 Desktop]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample  /etc/dhcpd.conf 
cp:是否覆盖“/etc/dhcpd.conf”? y


日志:

[root@station230 ~]# /etc/init.d/syslog restart
关闭内核日志记录器:                               [确定]
关闭系统日志记录器:                               [确定]
启动系统日志记录器:                               [确定]
启动内核日志记录器:                               [确定]


常用的日志:
[root@station230 log]# pwd
/var/log

message   系统日志文件
wtmp   用last命令查看
utmp    用who    w   users
lastlog    用lastlog命令查看
secure
boot.log
dmesg

xferlog   vsftp的日志文件
cron

mail  


配置文件:
/etc/syslog.conf
日志对象  日志级别   日志文件
日志对象: 
auth, authpriv,cron, daemon,  kern,  lpr,  mail,
mark,  news,  security  (same  asauth),  syslog,
user,  uucp  and local0  through local7.
日志级别:
debug, info, notice, warn-ing, warn (same as warning)
err,error (same as err)  
crit, alert,emerg,  panic  (same  as  emerg).

[root@station230 log]# man 5 syslog.conf 


[root@station230 log]# vim /etc/syslog.conf 
*.*    /var/log/mylog
mail.info
mail.=info
mail.!info

[root@station230 log]# touch mylog
[root@station230 log]# chmod 777 mylog
[root@station230 log]# tail -f mylog

[root@station230 log]# /etc/init.d/syslog restart

[root@station230 log]# tail -f mylog
Sep 16 11:40:36 station230 syslogd 1.4.1: restart (remote reception).
Sep 16 11:40:36 station230 kernel: klogd 1.4.1, log source = /proc/kmsg started.

远程日志:
产生日志的机器要修改:
/etc/syslog.conf
*.*                                         @192.168.100.51
日志服务器需要修改:
[root@station230 log]# vim /etc/sysconfig/syslog 
SYSLOGD_OPTIONS="-m 0 -r"    加-r

重启两台日志服务器:
/etc/init.d/syslog restart

日志轮转:
配置文件:
/etc/logrotate.conf
全局
局部

重启服务:
/etc/init.d/logrotate restart
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true

kill  -1  4487

计划任务:
一次性的计划任务:
at:
服务启动:/etc/init.d/atd restart
[root@station230 init.d]# at 13:50
at> rm -rf /tmp/*        
at> <EOT>
job 3 at 2012-09-16 13:50

查看:
[root@station230 init.d]# at -l
3       2012-09-16 13:50 a root
[root@station230 tmp]# atq
5       2012-09-16 14:30 a root

[root@station230 init.d]# at -l
[root@station230 init.d]# cd /tmp/
[root@station230 tmp]# ls
a

存放计划任务的文件:
[root@station230 at]# ls
a000040156c1c0  spool
[root@station230 at]# cat a000040156c1c0 
[root@station230 at]# pwd
/var/spool/at

删除at任务:
[root@station230 tmp]# at -l
5       2012-09-16 14:30 a root
[root@station230 tmp]# at -d 5
[root@station230 tmp]# atrm 5

开机启动和关闭:
[root@station230 tmp]# chkconfig --level 5 atd off
[root@station230 tmp]# chkconfig --level 5 atd on
[root@station230 tmp]# setup

循环性计划任务:
[root@station230 tmp]# /etc/init.d/crond status
crond (pid  2479) 正在运行...

[root@station230 tmp]# crontab -e
分钟  小时     日     月    周          动作
0-59   0-23    1-31   1-12   0-7
5       4       15     *     *
*/5   *       *     *    *
1,8,10   *       *    *     *
1-5,9-15  *      *    *    *

[root@station230 tmp]# man 5 crontab

查看:
[root@station230 cron]# crontab  -l
删除:
[root@station230 cron]# crontab -r -u user100
计划任务文件存储位置:
/var/spool/cron

Crontab 格式说明

 我们可以用crontab -e 添加要执行的命令。 命令执行的结果,无论是标准输出还是错误输出,都将以邮件形式发给用户。

   添加的命令必须以如下格式:

   * * * * * /command path

前五个字段可以取整数值,指定何时开始工作,第六个域是字符串,即命令字段,其中包括了crontab调度执行的命令。 各个字段之间用spaces和tabs分割。

5个字段分别表示:

       分钟:0-59

       小时:1-23

       日期:1-31

       月份:1-12

       星期:0-6(0表示周日)

还可以用一些特殊符号:

       *: 表示任何时刻

       ,: 表示分割

  -:表示一个段,如第二端里: 1-5,就表示1到5点

       /n : 表示每个n的单位执行一次,如第二段里,*/1, 就表示每隔1个小时执行一次命令。也可以写成1-23/1.

一些示例:

00 8,12,16 * * * /data/app/scripts/monitor/df.sh

30 2 * * * /data/app/scripts/hotbackup/hot_database_backup.sh

10 8,12,16 * * * /data/app/scripts/monitor/check_ind_unusable.sh

10 8,12,16 * * * /data/app/scripts/monitor/check_maxfilesize.sh

10 8,12,16 * * * /data/app/scripts/monitor/check_objectsize.sh

 

43 21 * * * 21:43 执行

15 05 * * *    05:15 执行

0 17 * * * 17:00 执行

0 17 * * 1 每周一的 17:00 执行

0,10 17 * * 0,2,3 每周日,周二,周三的 17:00和 17:10 执行

0-10 17 1 * * 毎月1日从 17:00到7:10 毎隔1分钟 执行

0 0 1,15 * 1 毎月1日和 15日和 一日的 0:00 执行

42 4 1 * *     毎月1日的 4:42分 执行

0 21 * * 1-6   周一到周六 21:00 执行

0,10,20,30,40,50 * * * * 每隔10分 执行

*/10 * * * *        每隔10分 执行

* 1 * * *         从1:0到1:59 每隔1分钟 执行

0 1 * * *         1:00 执行

0 */1 * * *        毎时0分 每隔1小时 执行

0 * * * *         毎时0分 每隔1小时 执行

2 8-20/3 * * *      8:02,11:02,14:02,17:02,20:02 执行

30 5 1,15 * *       1日 和 15日的 5:30 执行


后台执行命令

 当在前台运行某个作业时,终端被该作业占据;而在后台运行作业时,它不会占据终端。可以使用&命令把作业放到后台执行。

       如:

       30 2 * * * /data/app/scripts/hotbackup/hot_database_backup.sh &

       在后台运行作业时要当心:需要用户交互的命令不要放在后台执行,因为这样你的机器就会在那里傻等。

       不过,作业在后台运行一样会将结果输出到屏幕上,干扰你的工作。如果放在后台运行的作业会产生大量的输出,最好使用下面的方法把它的输出重定向到某个文件中:

       如:

              command >out.file 2>&1 &

     在这个例子中,2>&1表示所有的标准输出和错误输出都将被重定向到一个叫做out.file 的文件中。

2.4  2>&1 含义

先看一个例子:

0 2 * * * /u01/test.sh >/dev/null 2>&1 &

这句话的意思就是在后台执行这条命令,并将错误输出2重定向到标准输出1,然后将标准输出1全部放到/dev/null 文件,也就是清空。

在这里有有几个数字的意思:

       0表示键盘输入

       1表示标准输出

       2表示错误输出.

我们也可以这样写:

0 2 * * * /u01/test.sh  >/u01/out.file &  --这里没写,默认是1

0 2 * * * /u01/test.sh  1>/u01/out.file &

0 2 * * * /u01/test.sh  2>/u01/out.file &

0 2 * * * /u01/test.sh  2>/u01/out.file  2>&1 &

将tesh.sh 命令输出重定向到out.file, 即输出内容不打印到屏幕上,而是输出到out.file文件中。

2>&1 是将错误输出重定向到标准输出。 然后将标准输入重定向到文件out.file。

&1 表示的是文件描述1,表示标准输出,如果这里少了&就成了数字1,就表示重定向到文件1。

& :后台执行

测试:

ls 2>1 : 不会报没有2文件的错误,但会输出一个空的文件1;

ls xxx 2>1: 没有xxx这个文件的错误输出到了1中;

ls xxx 2>&1: 不会生成1这个文件了,不过错误跑到标准输出了;

ls xxx >out.txt 2>&1 == ls xxx 1>out.txt 2>&1;  因为重定向符号>默认是1,这句就把错误输出和标准输出都传到out.txt 文件中。

 2>&1写在后面的原因

       格式:command > file 2>&1   == command  1> file 2>&1

       首先是command > file将标准输出重定向到file中, 2>&1 是标准错误拷贝了标准输出,也就是同样被重定向到file中,最终结果就是标准输出和错误都被重定向到file中。

如果改成: command 2>&1 >file

       2>&1 标准错误拷贝了标准输出的行为,但此时标准输出还是在终端。>file 后输出才被重定向到file,但标准错误仍然保持在终端。


原创粉丝点击