
第一种方法:
用crontab命令就可以了,下面看一下它的详细用法。名称
:
crontab
使用权限
:
所有使用者
使用方式
:
crontab
[
-u
user
]
file
crontab
[
-u
user
]
{
-l
|
-r
|
-e
}
说明
:
crontab
是用来让使用者在固定时间或固定间隔执行程序之用,换句话说,也就是类似使用者的时程表。-u
user
是指设定指定
user
的时程表,这个前提是你必须要有其权限(比如说是
root)才能够指定他人的时程表。如果不使用
-u
user
的话,就是表示设定自己的时程表。
餐数
:
-e
:
执行文字编辑器来设定时程表,内定的文字编辑器是
VI,如果你想用别的文字编辑器,则请先设定
VISUAL
环境变数来指定使用那个文字编辑器(比如说
setenv
VISUAL
joe)
-r
:
删除目前的时程表
-l
:
列出目前的时程表
时程表的格式如下
:
f1
f2
f3
f4
f5
program
其中
f1
是表示分钟,f2
表示小时,f3
表示一个月份中的第几日,f4
表示月份,f5
表示一个星期中的第几天。program
表示要执行的程序。
当
f1
为
时表示每分钟都要执行
program,f2
为
时表示每小时都要执行程序,其馀类推
当
f1
为
a-b
时表示从第
a
分钟到第
b
分钟这段时间内要执行,f2
为
a-b
时表示从第
a
到第
b
小时都要执行,其馀类推
当
f1
为
/n
时表示每
n
分钟个时间间隔执行一次,f2
为
/n
表示每
n
小时个时间间隔执行一次,其馀类推
当
f1
为
a,
b,
c,
时表示第
a,
b,
c,
分钟要执行,f2
为
a,
b,
c,
时表示第
a,
b,
c个小时要执行,其馀类推
使用者也可以将所有的设定先存放在档案
file
中,用
crontab
file
的方式来设定时程表。
例子
:
每月每天每小时的第
0
分钟执行一次
/bin/ls
:
0
7
/bin/ls
在
12
月内,
每天的早上
6
点到
12
点中,每隔
20
分钟执行一次
/usr/bin/backup
:
0
6-12/3
12
/usr/bin/backup
周一到周五每天下午
5:00
寄一封信给
alex@domainname
:
0
17
1-5
-s
"hi"
alex@domainname
<
/tmp/maildata
每月每天的午夜
0
点
20
分,
2
点
20
分,
4
点
20
分执行
echo
"haha"
20
0-23/2
echo
"haha"
注意
:
当程序在你所指定的时间执行后,系统会寄一封信给你,显示该程序执行的内容,若是你不希望收到这样的信,请在每一行空一格之后加上
>
/dev/null
2>&1
即可
第二种方法:
使用shutdown定时关机的问题
shutdown:
invalid
option
--
-
Usage:
shutdown
[-akrhfnc]
[-t
secs]
time
[warning
message]
-a:
use
/etc/shutdownallow
-k:
don't
really
shutdown,
only
warn
-r:
reboot
after
shutdown
-h:
halt
after
shutdown
-f:
do
a
'fast'
reboot
(skip
fsck)
-F:
Force
fsck
on
reboot
-n:
do
not
go
through
"init"
but
go
down
real
fast
-c:
cancel
a
running
shutdown
-t
secs:
delay
between
warning
and
kill
signal
the
"time"
argument
is
mandatory!
(try
"now")
我是这样的shutdown
-t
54000
就是运行15小时后自动关机
这样行吗顺便问下,还有什么更好的方法自动关机吗
利用串口终端作为Linux控制台,可以免去额外的键盘,显示卡和显示器,同时可将Linux主机作为一个任意用途的嵌入式黑匣。那么LINUX控制台怎么定向到串口终端下面跟着学习啦小编一起来了解一下吧。LINUX控制台怎么定向到串口终端
目的: 台机已经装好Linux,显示器有问题,平时一般都SSH控制,当Linux网络挂的时候,想通过串口来管理。
硬件:台机自带两个串口(上面的是COM1)[under Windows] or ttyS0[under Linux)),笔记本T61p没有串口,买了个USB转串口(具体见下图)。同时需要串口交叉线一根(NULL modem Cable),母对母(公的是针),都是凹口那种。
目标机器:安装的CentOS 52 Linux 内核2618-92122el5和2618-92122el5xen
客户端: Windows XP SP3 IBM OEM 安装USB转串口驱动。
需要把输出定向到串口,一般有下面几处:
BIOS中的设置
GRUB设置
/etc/inittab 设置
/etc/securetty 设置
BIOS中的设置
BIOS设置的作用我没尝试过,如果是可以连BIOS设置都可以定向到串口,那个强大了。也不知道如何去掉机器需要连键盘的限制。没拿出显示器所以没看我台机的BIOS,不过这个功能一般只有服务器级别的机器有。注1台机一般没有串口重定向功能。
GRUB设置
这里的配置是为了把grub菜单定向到串口,这样你就可以在串口 *** 作grub,选择启动项,使用single mode等等。
同时也要给kernel参数加上console选项。
[root@CentOS5 ~]# cat /boot/grub/menulst
# grubconf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition This means that
# all kernel and initrd paths are relative to /boot/, eg
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/vg00/lv_root
# initrd /initrd-versionimg
#boot=/dev/hdb1
serial --unit=0 --speed=9600 --word=8 --parity=no --stop=1
terminal --timeout=10 serial console
default=2
timeout=20
#splashimage=(hd0,0)/grub/splashxpmgz =>这些在console下会工作不正常,注释掉。
#hiddenmenu
title CentOS (2618-92122el5)
root (hd0,0)
kernel /vmlinuz-2618-92122el5 ro root=/dev/vg00/lv_root rhgb quiet
initrd /initrd-2618-92122el5img
title CentOS Serial[ttyS0] - Console (2618-92122el5)
root (hd0,0)
kernel /vmlinuz-2618-92122el5 ro root=/dev/vg00/lv_root console=ttyS0,9600 console=tty0
initrd /initrd-2618-92122el5img
title CentOS Console - serial[ttyS0] (2618-92122el5) [get more output in serial console]
root (hd0,0)
kernel /vmlinuz-2618-92122el5 ro root=/dev/vg00/lv_root console=tty0 console=ttyS0,9600
initrd /initrd-2618-92122el5img
title CentOS Xen (2618-9212
我给你吧~
#include <stdioh>
#include <sys/typesh>
#include <direnth>
#include <sys/stath>
#include <stringh>
char c="c";
char cpp="cpp";
char gcc="gcc ";
char o="-o ";
char dot="";
char dotdot="";
void do_search_dir(char path) {
DIR dir;
char fullpath[1024],currfile[1024];
struct dirent s_dir;
struct stat file_stat;
strcpy(fullpath,path);
dir=opendir(fullpath);
while ((s_dir=readdir(dir))!=NULL) {
if ((strcmp(s_dir->d_name,dot)==0)||(strcmp(s_dir->d_name,dotdot)==0))
continue;
sprintf(currfile,"%s/%s",fullpath,s_dir->d_name);
stat(currfile,&file_stat);
if (S_ISDIR(file_statst_mode))
do_search_dir(currfile);
else
{
char p;
p=currfile;
while(p)p++;
while(p>currfile && p!='')p--;
if (p!=currfile)p++;
if(strncmp(p,c,1)==0 || strncmp(p,cpp,3)==0)
system(strcat(gcc,strcat(currfile,strcat(o,currfile))));
}
}
closedir(dir);
}
int main() {
do_search_dir(dot);
return 0;
}
代理服务器(Proxy Server)是个人网络和Internet服务商之间的中间代理机构,它负责转发合法的网络信息,对转发进行控制和登记。
代理服务器作为连接Internet(广域网)与Intranet(局域网)的桥梁,在实际应用中发挥着极其重要的作用。
Linux下有很多程序都只有命令行接口,对于这类程序,它们通过代理服务器(proxy)访问网络的方式也不尽相同。
本文总结了一些常用Windows/Linux程序配置代理服务器的方法。
对于大多数Linux控制台程序,例如 Debian 或Ubuntu中的apt-get和aptitude命令、 git命令 、wget命令,这些程序都使用>
修改 /etc/inittab 文件,将“id:5:initdefault:”这一行的"id:"后的数字(默认为5)改为 3即可。 Linux将X-Window(简称X)仅仅视作一个程序,而不捆绑于其内核之中。在UNIX/Linux中一般将运行级别分为7级(一说九级,但实际应用为六级,保留一级
以上就是关于linux系统在控制台下每天的定时关机指令如何编写全部的内容,包括:linux系统在控制台下每天的定时关机指令如何编写、怎么切换到linux串口调试控制台、Linux系统可以运行Windows的控制台程序吗等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)