如何實現linux单机autolinux reboott 100次

Linux_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
&&网络工程师
网络工程师 基础
你可能喜欢新手园地& & & 硬件问题Linux系统管理Linux网络问题Linux环境编程Linux桌面系统国产LinuxBSD& & & BSD文档中心AIX& & & 新手入门& & & AIX文档中心& & & 资源下载& & & Power高级应用& & & IBM存储AS400Solaris& & & Solaris文档中心HP-UX& & & HP文档中心SCO UNIX& & & SCO文档中心互操作专区IRIXTru64 UNIXMac OS X门户网站运维集群和高可用服务器应用监控和防护虚拟化技术架构设计行业应用和管理服务器及硬件技术& & & 服务器资源下载云计算& & & 云计算文档中心& & & 云计算业界& & & 云计算资源下载存储备份& & & 存储文档中心& & & 存储业界& & & 存储资源下载& & & Symantec技术交流区安全技术网络技术& & & 网络技术文档中心C/C++& & & GUI编程& & & Functional编程内核源码& & & 内核问题移动开发& & & 移动开发技术资料ShellPerlJava& & & Java文档中心PHP& & & php文档中心Python& & & Python文档中心RubyCPU与编译器嵌入式开发驱动开发Web开发VoIP开发技术MySQL& & & MySQL文档中心SybaseOraclePostgreSQLDB2Informix数据仓库与数据挖掘NoSQL技术IT业界新闻与评论IT职业生涯& & & 猎头招聘IT图书与评论& & & CU技术图书大系& & & Linux书友会二手交易下载共享Linux文档专区IT培训与认证& & & 培训交流& & & 认证培训清茶斋投资理财运动地带快乐数码摄影& & & 摄影器材& & & 摄影比赛专区IT爱车族旅游天下站务交流版主会议室博客SNS站务交流区CU活动专区& & & Power活动专区& & & 拍卖交流区频道交流区
白手起家, 积分 6, 距离下一级还需 194 积分
论坛徽章:0
请教高手,如何在linux单机下完成系統自動 reboot 100次? 可否将代碼贴出來给大家!甚谢!!
&&nbsp|&&nbsp&&nbsp|&&nbsp&&nbsp|&&nbsp&&nbsp|&&nbsp
论坛徽章:0
你让你系统启动之后自动执行一个程序, 这个程序先去读取你文件系统上的一个数字, 初始为101, 然后将其减1. 判断其是否大于0. 如果大于0 则重启. 就可以了啊.
白手起家, 积分 6, 距离下一级还需 194 积分
论坛徽章:0
你可以在你機器上嘗試一下吗?我也在嘗試。谢谢!
论坛徽章:95
回复 #3 steven-lee 的帖子
你自己尝试下就可以了。
白手起家, 积分 6, 距离下一级还需 194 积分
论坛徽章:0
# vi reboot.sh
for ((n=1;n&100;n++))
echo & Times=$n , start at `date` && /root/reboot_log.txt
reboot -n -f
可以用以上的for循环来控制它吗? 而且让 reboot.sh 開機自動執行的话,会不会導致系統一直reboot下去, 我很擔心这个問題,请高手指點!!
论坛徽章:0
你的这个 n ,重新运行之后又是 1 了。
应该用一个文件来存储重启的次数。
家境小康, 积分 1856, 距离下一级还需 144 积分
论坛徽章:0
if [ ! -x /root/reboot_log.txt ]; then
echo & Times=0 , start at `date`& && /root/reboot_log.txt
for ((n=`cat /root/reboot_log.txt|awk '{print substr($1,7)}'`;n&100;n++))
echo & Times=$n , start at `date`& && /root/reboot_log.txt
reboot -n -f
[ 本帖最后由 wysilly 于
17:21 编辑 ]
白手起家, 积分 6, 距离下一级还需 194 积分
论坛徽章:0
感謝wysilly!!!
白手起家, 积分 4, 距离下一级还需 196 积分
论坛徽章:0
LZ你好,我对你提的这个问题也很感兴趣。不知道你是否已经实现了。可否花你点点时间告示我如何实现?
请详细点如何?因为我是个新手,
试图给你发mail,但是不知道为何,邮件被退。如果方便联系
万分感激。
白手起家, 积分 4, 距离下一级还需 196 积分
论坛徽章:0
能否传授如何操作,才能让系统启动后能自动运行我们编辑的脚本。
希望你能不惜赐教。在下愚昧,
先谢过了。
如果方便上面mail联系更为感谢。1156人阅读
C语言(7)
Linux(9)
原文地址:
当然你也可以直接调用system(&reboot&),但是这里完全基于库函数来实现,不依赖于/sbin/reboot这个外部程序
这里reboot()的其他命令,比如RB_POWER_OFF,并不能保证关闭计算机电源.
#include &unistd.h&
#include &sys/reboot.h&
int main()
&&& sync(); //&同步磁盘数据,将缓存数据回写到硬盘,以防数据丢失[luther.gliethttp]
&&& return reboot(RB_AUTOBOOT);
luther@gliethttp:~$ vim /usr/include/sys/reboot.h
/* Copyright (C) ,
Free Software Foundation, Inc.
&& This file is part of the GNU C Library.
&& The GNU C Libr you can redistribute it and/or
&& modify it under the terms of the GNU Lesser General Public
&& License as published by the Free Software F either
&& version 2.1 of the License, or (at your option) any later version.
&& The GNU C Library is distributed in the hope that it will be useful,
&& but WITHOUT ANY WARRANTY; without even the implied warranty of
&& MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.& See the GNU
&& Lesser General Public License for more details.
&& You should have received a copy of the GNU Lesser General Public
&& License along with the GNU C L if not, write to the Free
&& Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
/* This file should define RB_* macros to be used as flag
&& bits in the argument to the `reboot' system call.& */
#ifndef _SYS_REBOOT_H
#define _SYS_REBOOT_H&&& 1
#include &features.h&
/* Perform a hard reset now.& */
#define RB_AUTOBOOT&&& 0x
/* Halt the system.& */
#define RB_HALT_SYSTEM&&& 0xcdef0123
/* Enable reboot using Ctrl-Alt-Delete keystroke.& */
#define RB_ENABLE_CAD&&& 0x89abcdef
/* Disable reboot using Ctrl-Alt-Delete keystroke.& */
#define RB_DISABLE_CAD&&& 0
/* Stop system and switch power off if possible.& */
#define RB_POWER_OFF&&& 0x4321fedc
__BEGIN_DECLS
/* Reboot or halt the system.& */
extern int reboot (int __howto) __THROW;
__END_DECLS
#endif&&& /* _SYS_REBOOT_H */
luther@gliethttp:~$ man 2 reboot
REBOOT(2)&&&&&&&&&&&&&&&&& Linux Programmer’s Manual&&&&&&&&&&&&&&&& REBOOT(2)
&&&&&& reboot - reboot or enable/disable Ctrl-Alt-Del
&&&&&& /* For libc4 and libc5 the library call and the system call
&&&&&&&&& are identical, and since kernel version 2.1.30 there are
&&&&&&&&& symbolic names LINUX_REBOOT_* for the constants and a
&&&&&&&&& fourth argument to the call: */
&&&&&& #include &unistd.h&
&&&&&& #include &linux/reboot.h&
&&&&&& int reboot(int magic, int magic2, int cmd, void *arg);
&&&&&& /* Under glibc some of the constants involved have gotten
&&&&&&&&& symbolic names RB_*, and the library call is a 1-argument
&&&&&&&&& wrapper around the 3-argument system call: */
&&&&&& #include &unistd.h&
&&&&&& #include &sys/reboot.h&
&&&&&& int reboot(int cmd);
DESCRIPTION
&&&&&& The& reboot()& call& reboots the system, or enables/disables the reboot
&&&&&& keystroke (abbreviated CAD, since the default& is& Ctrl-Alt-D& it
&&&&&& can be changed using loadkeys(1)).
&&&&&& This&& system&& call& will& fail& (with& EINVAL)& unless& magic& equals
&&&&&& LINUX_REBOOT_MAGIC1&& (that&& is,&& 0xfee1dead)&& and&& magic2&& equals
&&&&&& LINUX_REBOOT_MAGIC2& (that& is, ).& However, since 2.1.17 also
&&&&&& LINUX_REBOOT_MAGIC2A& (that& is,& )& and& since&& 2.1.97&& also
&&&&&& LINUX_REBOOT_MAGIC2B&& (that& is,& )& and& since& 2.5.71& also
&&&&&& LINUX_REBOOT_MAGIC2C (that is, ) are permitted& as& value& for
&&&&&& magic2.&& (The& hexadecimal& values of these constants are meaningful.)
&&&&&& The cmd argument can have the following values:
&&&&&& LINUX_REBOOT_CMD_RESTART
&&&&&&&&&&&&& (RB_AUTOBOOT, 0x1234567).& The message &Restarting& system.&& is
&&&&&&&&&&&&& printed, and a default restart is performed immediately.& If not
&&&&&&&&&&&&& preceded by a sync(2), data will be lost.
&&&&&& LINUX_REBOOT_CMD_HALT
&&&&&&&&&&&&& (RB_HALT_SYSTEM, 0xcdef0123; since 1.1.76).& The message &System
&&&&&&&&&&&&& halted.& is printed, and the system is halted.& Control is given
&&&&&&&&&&&&& to the ROM monitor, if there is& one.&& If& not& preceded& by& a
&&&&&&&&&&&&& sync(2), data will be lost.
&&&&&& LINUX_REBOOT_CMD_POWER_OFF
&&&&&&&&&&&&& (0x4321& since& 2.1.30).&& The& message& &Power& down.&& is
&&&&&&&&&&&&& printed, the system is stopped, and all power& is& removed& from
&&&&&&&&&&&&& the& system,& if& possible.&& If not preceded by a sync(2), data
&&&&&&&&&&&&& will be lost.
&&&&&& LINUX_REBOOT_CMD_RESTART2
&&&&&&&&&&&&& (0xa1b2c3d4; since 2.1.30).& The message &Restarting system with
&&&&&&&&&&&&& command& '%s'&& is& printed,& and& a& restart (using the command
&&&&&&&&&&&&& string given in arg) is performed immediately.& If not& preceded
&&&&&&&&&&&&& by a sync(2), data will be lost.
&&&&&& LINUX_REBOOT_CMD_CAD_ON
&&&&&&&&&&&&& (RB_ENABLE_CAD,& 0x89abcdef).&& CAD is enabled.& This means that
&&&&&&&&&&&&& the CAD keystroke will immediately cause the& action& associated
&&&&&&&&&&&&& with LINUX_REBOOT_CMD_RESTART.
&&&&&& LINUX_REBOOT_CMD_CAD_OFF
&&&&&&&&&&&&& (RB_DISABLE_CAD,& 0).& CAD is disabled.& This means that the CAD
&&&&&&&&&&&&& keystroke will cause a SIGINT signal to be sent to init (process
&&&&&&&&&&&&& 1),& whereupon& this& process& may& decide& upon a proper action
&&&&&&&&&&&&& (maybe: kill all processes, sync, reboot).
&&&&&& Only the superuser may call reboot().
&&&&&& The precise effect of the above actions depends& on& the& architecture.
&&&&&& For the i386 architecture, the additional argument does not do anything
&&&&&& at present (2.1.122), but the type of reboot can be determined by& ker‐
&&&&&& nel& command-line& arguments& (&reboot=...&) to be either warm or cold,
&&&&&& and either hard or through the BIOS.
RETURN VALUE
&&&&&& For the values of cmd that stop or restart& the& system,& a& successful
&&&&&& call& to& reboot()& does not return.& For the other cmd values, zero is
&&&&&& returned on success.& In all cases, -1& is& returned& on& failure,& and
&&&&&& errno is set appropriately.
&&&&&& EFAULT Problem&&&&& with&&&&& getting&&&&& userspace&&&& data&&&& under
&&&&&&&&&&&&& LINUX_REBOOT_CMD_RESTART2.
&&&&&& EINVAL Bad magic numbers or cmd.
&&&&&& EPERM& The calling process has insufficient privilege to call reboot();
&&&&&&&&&&&&& the CAP_SYS_BOOT capability is required.
CONFORMING TO
&&&&&& reboot() is Linux-specific, and should not be used in programs intended
&&&&&& to be portable.
&&&&&& sync(2),&& bootparam(7),&& capabilities(7),&& ctrlaltdel(8),&& halt(8),
&&&&&& reboot(8)
&&&&&& This& page& is& part of release 3.01 of the Linux man-pages project.& A
&&&&&& description of the project, and information about reporting& bugs,& can
&&&&&& be found at http://www.kernel.org/doc/man-pages/.
Linux&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&& REBOOT(2)
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:13028次
排名:千里之外
转载:18篇
(1)(1)(4)(3)(2)(1)(4)(4)(1)
(window.slotbydup = window.slotbydup || []).push({
id: '4740881',
container: s,
size: '200,200',
display: 'inlay-fix'Lazy Linux Admins Going to Server Rooms Less: Forced Reboot, Auto Reboot after Kernel Panic... - 推酷
Lazy Linux Admins Going to Server Rooms Less: Forced Reboot, Auto Reboot after Kernel Panic...
Having to go the the server room to reset servers is the most headache thing for admins managing a cluster of Linux servers in a remote site. Either you can ping the server but can not ssh to it, or you even can not ping it. There are various reasons that may cause a Linux server crash or fail to be connected to by SSH. The most common two from my experience are: there may be a bad behaving progress that use up almost all physical memory and swap or there may be a kernel panic. In this post, I describe several techniques I learned to make myself go to the server room less by dealing with these kinds of failures.
Force Linux to reboot even you could not start a shell via SSH∞
If the server is too busy, creating the shell via SSH may also fail even though sshd is alive. Some times, you get lucky that you can remotely execute some commands by ssh directly. You may try to make use of the magical SysRq to force Linux to restart.
ssh root@server_home \
'echo 1 & /proc/sys/kernel/ echo b & /proc/sysrq-trigger'
Reference:
After this command, if you find your server disappear from the network, it may be rebooting itself. Wait for a while and it may come back.
Make Linux reboot automatically after a kernel panic∞
Some times, you get bad luck that there is a kernel panic. Almost everything including the network stop working and you can not connect to the server any more. That is not good but may not be too bad if we did some home work before by configuring Linux to reboot itself after kernel panics.
Linux has a nice feature that reboots itself after a timeout if a kernel panic happened. Usually, it is disabled. We can turn it on as we are lazy system admins. It can be enabled by setting the
kernel.panic
kernel parameter.
For a running system:
# echo 20 &/proc/sys/kernel/panic
Here, 20 is the number of seconds before the kernel reboots. 0 means this feature is disabled.
To make the configuration persistent, you have at least 2 choices:
add the kernel parameter
to your bootloader (grub or grub2).
kernel.panic = 20
to /etc/sysctl.conf .
I prefer the second method that writes the configuration to /etc/sysctrl.conf.
For more details, please check
Email notifications after Linux reboot∞
Auto reboot is good. It will be better that the server also notifies the admins after a reboot. The technique discussed at
makes the server send email notifications after reboots.
It makes use of the
cron jobs and
by adding an entry like
@reboot date | mailx -S smtp=smtp:// -s &`hostname` started& -r
For sending emails, you may either
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致请问Linux/SuSE 下系统reboot 100 times的脚本,多谢!_读书人
请问Linux/SuSE 下系统reboot 100 times的脚本,多谢!
&来源:读书人网&【读书人网():综合教育门户网站】
请教Linux/SuSE下系统reboot 100 times的脚本,谢谢!!!由於手上有一project需要做系yreboot(不断电),O
请教Linux/SuSE 下系统reboot 100 times的脚本,谢谢!!!由於手上有一project需要做系yreboot(不断电),OS为Linux/SuSE.要求:1)正常开关机100次& 2)自F3)用_本或Z言F由於每次手硬僮饔X得^於笨拙,在此特教Linux高手,如何通^_本或程式碜FLinux下reboot 100 times功能?& 谢谢指教!!![解决办法]看了一下,脚本也有错,应改为#!/bin/sh #chkconfig:
#desprication: automatic reboot for 100 times \& # add& countfile=/var/log/reboot.auto tmpfile=/var/log/reboot.auto.tmp count=0 case &$1 & in start)
count=`/bin/cat $countfile 2& /dev/null`
count=expr $count + 1
if [ $count -lt 101 ] ; then { echo $count & $tmpfile 2& /dev/null } && { mv -f $tmpfile $countfile 2& /dev/null} && { /sbin/init 6 }&
;; *) ;;& esac你试试吧,如果不行,可以看看/etc/init.d/的文件里人家是怎么写的,然后自己改

我要回帖

更多关于 linux reboot 的文章

 

随机推荐