|

楼主 |
发表于 2006-1-10 09:24:57
|
显示全部楼层
Post by d00m3d
Ha...Ha...I am doing the same things as you in the office.
I am not aware of any software in that sort. Well, if you find one, please let me know.
实在没找到什么好的软件来帮忙,自己写了一个
还是很麻烦,最好是要把所有的系统的boot/grub/menu.lst 都指向一个公共分区上的文件
而且系统负载很大的时候不要用,一旦menu.lst修改失败,就很麻烦了,其实最简单用shell写
几行就可以写完。
我还是继续走几步过去重起,不用这个脚本,怕menu.lst放在公共部分给别的人造成麻烦那:beat
[PHP]
#!/usr/bin/perl
# $id: auto rebooter 2006-01-09
#
# suport less then 10 boot opinion
# do not use this on important machines
# this may damage you box
#my $conf="/boot/grub/menu.lst";
my $conf="grub.conf"; ###修改这里
open (FD,"<$conf") || die "can not open grub config file !\n";
my @cont=<FD>;
close FD;
my $count=0;
my $posi =0;
my $i =0;
my @list =();
if (!-f $conf.".baK"){
print "backuping grub config file to $conf.baK....";
open (FD2,"+>",$conf.".baK")||die "can not open $conf.baK !\n";
print FD2 "@cont\n";
close FD2;
print "OK\n";
}
my @cont2=@cont;
for $line (@cont){
chomp $line;
$i++;
if ($line =~/^#/){
next;
}elsif ($line=~/default.*(\d)/){
$def=$1;
$posi=$i;
}elsif($line=~s/.*title\s+//){
push @list,$line;
$count++;
}
}
if ($count eq 0){
print "no boot item found, please check your $conf\n";
exit;
}
if (!(defined $def)){
print "no default boot opinion found, please check your $conf\n";
exit;
}
my $ret=0;
do{
&printlist(\@list,$def);
}while(1);
sub cprint()
{
my $head=shift;
my $msg=shift;
print "$head";
printf "\x1b[7m%-54s\x1b[m|\n",$msg;
}
sub printlist()
{
my($list,$def2)=@_;
my $i=0;
system("clear");
print "\n\n\t+-------------------------------------------------------------+\n";
for $os (@$list){
chomp $os;
if($i == $def2){
&cprint("\t| $i\t",$os);
}else{
printf("\t| %d\t%-54s",$i,$os);
print "|\n";
}
$i++;
}
print "\t+-------------------------------------------------------------+\n\n\n\n";
print "[0-$#list] for OS, b to boot, q to cancel\n";
#print "default boot is $def: @list[$def]\n";
print "BOOT: $def>";
&getcmd();
}
sub getcmd()
{
my $c = getc(STDIN);
if ($c =~ /q/i){
exit;
}elsif($c =~ /b/i){
&boot();
}else{
my $t = ord $c;
$t-=48;
if ($t >=0 && $t <=$#list){
$def= $t;
}
}
}
sub boot()
{
open (FD,">$conf")||die "can not open $conf !\n";
@cont2[--$posi]="default $def\n";
#print FD "@cont2\n";
for (0..$#cont2){
print FD "@cont2[$_]";
}
close FD;
print "\nrebooting....\n";
`shutdown -r -t0 now`;
exit;
}
[/PHP] |
|