Machinfo.pl
machinfo.pl – Skriptík na uložení kruciálních dat o stroji
#! /usr/bin/perl
# machinfo - Basic info of this machine
@disks = ('hda', 'hdb', 'hdc', 'hdd');
open (HOSTNAME, "/etc/hostname");
$hostname = <HOSTNAME>;
chop $hostname;
close HOSTNAME;
print "$hostname";
#print `date`;
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
$year += 1900;
#print "$mday.$mon.$year-$hour:$min\n";
$year -= 2000;
$mon++;
$dattime = sprintf ("%02d%02d%02d-%02d%02d", $year, $mon, $mday, $hour, $min);
print "/$dattime\n";
&cmd ("mkdir $dattime");
chdir $dattime;
print `cp ../comment0.txt comment.txt`;
print `echo date-time: $dattime >> comment.txt`;
print `echo -n 'hostname: ' >> comment.txt`;
print `hostname >> comment.txt`;
print `uname -a >> comment.txt`;
print `host $hostname >> comment.txt`;
# print `jmacs comment.txt`;
system ('jmacs comment.txt');
foreach $disk(@disks)
{
&cmd ("dd if=/dev/$disk count=1 ibs=512 of=parttbl.$disk")
&cmd ("perl ../diskinfo.pl $disk > diskinf.$disk");
}
&cmd ("cp -p /etc/fstab .");
&cmd ("cp -p /etc/lilo.conf .");
&cmd ("cp -p /boot/grub/device.map .");
&cmd ("cp -p /boot/grub/menu.lst .");
&cmd ("dmesg > dmesg.txt");
&cmd ("df > df.txt");
print `pwd`;
&cmd ("ls -l");
chdir '..';
$tarfile = "$hostname-$dattime-info.tgz";
&cmd ("tar czvf $tarfile $dattime");
&cmd ("ls -l $tarfile");
&cmd ("tar tzf $tarfile");
#################################################################
sub cmd
{
local ($cmd) = @_;
print "$cmd\n";
print `$cmd`."\n";
print "\n";
}