系統比對[oscmp.pl](轉)
系統比對[oscmp.pl](轉)[@more@] #!/usr/bin/perl -w ########################################################################### # Global definitions ########################################################################### use Getopt::Long; $tmpdir="/usr/tmp/integrit.$$"; $usrtmp="/usr/tmp/integrit_tmp.$$"; $filedir="$tmpdir/filedir"; $integrit_conf="$tmpdir/integrit.conf"; $integrit="/usr/local/sbin/integrit"; $knowndb="/tmp/tsecdb"; $remcurrentdb="/tmp/databases/integrit.cdb.new"; $currentdb="/tmp/databases"; $remdb="/tmp/tsecdb/integrit.cdb"; $inststuff="/ccrun/etc/inststuff.pl"; ########################################################################### #command ########################################################################### #$scp="/usr/bin/scp"; #$ssh="/usr/local/bin/ssh"; #$rsync="/usr/bin/rsync"; #$integrit="/usr/bin/integrit"; $scp="/usr/local/bin/scp"; $ssh="/usr/local/bin/ssh"; $rsync="/usr/local/bin/rsync"; $integrit="/usr/local/sbin/integrit"; $rsync_cmd="$rsync -Rapzq --partial -e $ssh"; $rsync_del="$rsync -lvrnc --delete -e $ssh"; $rsync_exist="$rsync -lvrnc --existing -e $ssh"; ########################################################################### # Check for help request. Display help page if --help/-h/-? was passed. ########################################################################### sub help_page { my $programname = $0; $programname =~ s#^./##; print("$programname - . Usage: $programname [-i Ign] Options are interpreted as follows: -r hostname remote hostname -i Ign Ignores default setting. For example: $programname -r enghp3
"); exit 1; } ########################################################################### # Check and update local configuration ########################################################################### sub LocalVarExists ($) { my ($name) = @_; return $main::{$name}; # if integrit_conf declared it, we're done. } my $newstuff = ""; sub LocalVar ($$) { my ($name, $definition) = @_; return if $main::{$name}; $newstuff .= " " . $name; open FILE, '>>', $integrit_conf; print FILE $definition, "
"; close FILE; } ########################################################################### # Check data directory ########################################################################### sub Checkdir() { #Check tmp directory unless (-d $tmpdir) { print "Creating tmp directory ($tmpdir) ...
"; mkdir $tmpdir, 0770; } unless (-d $usrtmp) { print "Creating tmp directory ($usrtmp) ...
"; mkdir $usrtmp, 0770; } unless (-d $knowndb) { print "Creating knowndb directory ($knowndb) ...
"; mkdir $knowndb, 0770; } #unless (-d $datadir) { # print "Creating data directory ($datadir) ...
"; # mkdir $datadir, 0770; #} ########################################################################### #create integrit.conf ########################################################################### unless (-e $integrit_conf){ LocalVar('root_dir', < # integrit.conf -*- fundamental -*- # root=/ END LocalVar('database', < known=/tmp/tsecdb/integrit.cdb current=/tmp/databases/integrit.cdb.new END LocalVar('README', < # from the integrit README file: # # Here's a table of letters and the corresponding checks / options: # # s checksum # i inode # p permissions # l number of links # u uid # g gid # z file size (redundant if checksums are on) # a access time # m modification time # c ctime (time UN*X file info last changed) # r reset access time (use with care) # # Upper case turus off a given check, Lower case turns it on. # # Files whose contents are expected to change only get checks on # permissions, user owner and group owner of the file. END LocalVar('SIMC', < # # For /root/ # !/root !/dev !/var !/tmp !/mnt !/.security !/home !/ora_system !/redund !/stand !/tcb !/mnt !/etc !/opt/hpws/tomcat !/opt/hpwebadmin !/opt/ignite !/usr/goldimage !/usr/adm !/usr/mail !/usr/spool !/usr/tmp !/usr/lost+found !/usr/preserve !/usr/spool !/usr/pub !/usr/share/man !/usr/share/doc !/usr/share/html !/usr/local/man !/usr/local/info !/usr/local/doc !/usr/local/oracle !/usr/local/src !/opt/samba_src !/opt/java1.3 !/opt/mozilla # # For /etc/ # !/etc/mtab SIMC !/etc/ssh_random_seed !/etc/fstab !/etc/mnttab !/etc/utmp !/etc/rc.config.d !/etc/ipf/ipmon.pid !/etc/opt/ldapux !/etc/opt/mx !/etc/sfd.pid !/etc/ftpd !/etc/MANPATH !/etc/PATH !/etc/skel !/etc/pam.conf !/etc/default !/etc/useracct !/etc/utmps !/etc/utmps !/etc/shutdownlog !/etc/issue !/etc/syslog.conf #/etc CMPILUGA #--------------nfs directories !/mnt/secdb !/barhost-home !/adm/barhost-cgi END LocalVar('Nocheck', < #--------this one gets over-written at boot, so only report changes # in its contents # No Check. The infomation is local filesystem info which depend on local host. !/etc/lvmconf !/etc/lvmrc !/etc/lvmtab !/etc/lvm* !/etc/vxvmconf !/etc/vx !/dev/vx !/var/vx !/usr/tmp !/dev/vg* !/dev/vxportal !/etc/.profile.* !/etc/fstab !/etc/aliases !/etc/oratab !/etc/passwd !/etc/group !/etc/opt/resmon !/etc/hosts !/etc/publickey !/etc/rc.config.d/netconf !/etc/ioconfig !/stand END LocalVar('checkdir', < #: Check dir. /opt CMPILUGA /bin CMPILUGA #/etc CMPILUGA /lib CMPILUGA /net CMPILUGA /sbin CMPILUGA /usr CMPILUGA /pcrelease CMPILUGA END } unless (-d $knowndb && -d $currentdb) { print "Creating known db directory or current db directory ...
"; mkdir $knowndb, 0770; mkdir $currentdb, 0770; } } sub GetParas { my ($argv); $argv = join(' ',@ARGV); $argv = join(' ',@ARGV); my $tmp = 0; &help_page if ( $argv eq "" || $argv =~ m!-h! ); GetOptions("r:s","i=s"); if ($opt_r eq "") { &help_page; exit(1); } if (! $opt_i eq "") { $tmp = $opt_i; } return ($opt_r,$tmp); } sub Env{ if ($> != 0) { print ("
The command need root permission!
"); exit(1); } } sub dbsh ($$){ my ($name, $definition) = @_; return if $main::{$name}; $newstuff .= " " . $name; open FILE, '>>', "$tmpdir/createdb.sh"; print FILE $definition, "
"; close FILE; } ########################################################################### #create creatdb.sh ########################################################################### sub newdbsh{ dbsh('createdbsh', < #!/bin/bash #Define work direction and command integrit_conf=`pwd`/integrit.conf integrit=/usr/local/sbin/integrit #scp=/usr/bin/scp #tmpdir=/usr/tmp/integrit.$$ currentdir=/tmp/databases/ currentdb=/tmp/databases/integrit.cdb.new #if [ ! -d $tmpdir ]; then # echo Creating $tmpdir directory >&2 # mkdir -p $tmpdir #fi if [ ! -d $currentdir ]; then echo Creating $currentdir directory >&2 mkdir -p $currentdir fi ls -l / |grep "^d" |awk '{print "!/"$9}' |grep -v "usr" |grep -v "opt" |grep -v "home"|grep -v "var" |grep -v "root" |grep -v "sbin"|grep -v "bin" |grep -v "net" |grep -v "^dev"| grep -v "etc" |grep -v "lib" | grep -v "pcrelease" >>$integrit_conf $integrit -u -C $integrit_conf END } ########################################################################### #Check host ########################################################################### sub Checkhost() { my ($thost) = @_; print "Warning - remote system is $thost- are you sure? (Y/N) "; my $tmp = ; if ($tmp eq "Y" && $tmp eq "y") { print "remote system is $thost
"; } else { exit 1; } } ########################################################################### #Get remote host db file ########################################################################### sub Getdb { my ($rhost) = @_; &newdbsh; system("ssh $rhost -l root '. /etc/.profile; mkdir $tmpdir'"); system("$scp $tmpdir/createdb.sh root@$rhost:$tmpdir"); system("$scp $integrit_conf root@$rhost:$tmpdir"); print "Creating integrit db file on $rhost ......
"; system("ssh $rhost -l root '. /etc/.profile;cd $tmpdir; sh createdb.sh'"); system("$scp root@$rhost:$remcurrentdb $remdb"); system("ssh $rhost -l root '. /etc/.profile; rm -rf $tmpdir"); } ########################################################################### #Copy file to tmpdir ########################################################################### sub cpfile{ my ($usrdir,$filelists) = @_; #copy file from local host to tmpdir open(FILE,"$usrdir/$filelists") || die "can not open filelist:$!"; while($filename=) { chomp($filename); if (! $filename eq "") { my $bar=`dirname $filename`; # system("mkdir -p $usrdir/filedir$bar"); system("$rsync_cmd $filename $usrdir/filedir 2>/dev/null"); } } } ########################################################################### #check file list ########################################################################### sub checkfilelist { my ($chfile) = @_; foreach $exist (`cat $tmpdir/$chfile`) { chomp($exist); if (! -e $exist) { open (FILE, ">>$usrtmp/$chfile"); print FILE "$exist
"; } } } ########################################################################### #check not exist file list ########################################################################### sub checknotexist { my ($checkfile) = @_; foreach $notexist (`cat $tmpdir/$checkfile`) { chomp($notexist); if (-e $notexist) { open (FILE, ">>$usrtmp/$checkfile"); print FILE "$notexist
"; } } } ########################################################################### #cleanup ########################################################################### sub cleanup { system("rm -rf $tmpdir"); } ########################################################################### #Main routine ########################################################################### sub main { my $help = grep(/^--help$/, @ARGV) || grep (/^-h$/, @ARGV) || grep (/^-?$/, @ARGV) || 0; help_page() if $help; #check user uid &Env; #Get hostname my ($host,$Ignores)=&GetParas; #check host print ("Warning - remote system is $host- are you sure? (Y/N)"); my $tmp = ; chomp($tmp); if ($tmp eq "Y" or $tmp eq "y") { print "remote system is $host
"; } else { exit 1; } #check data dir &Checkdir; #Get remote db file &Getdb($host); #no check dirs list system("ls -1 / |grep -v "usr" |grep -v "opt"|grep -v "home"|grep -v "var" |grep -v "root" |grep -v "sbin"|grep -v "bin"|grep -v "net"|grep -v "^dev" |grep -v "etc" |grep -v "lib" | grep -v "pcrelease" > $tmpdir/rootdirs "); foreach $dir (`cat $tmpdir/rootdirs`) { open (FILE, ">>$integrit_conf"); print FILE "!/$dir"; close (FILE); } #create integrit database on v44 and v45 hosts system("$integrit -u -C $integrit_conf"); system("$integrit -c -C $integrit_conf |grep -v "^integrit: ">$tmpdir/diffs"); system("cat "$tmpdir/diffs" |perl -pi -e 's!.*: +!!g' |perl -pi -e 's! +.*!!g'|sort |uniq |grep -v "#" >$tmpdir/diffs_file_list"); #Creating filelist print "Creating filelist file from $tmpdir/diffs_file_list .....
"; foreach my $list(`cat $tmpdir/diffs_file_list`) { chomp($list); open (FILE, ">>/$usrtmp/filelist"); print FILE "$list
" if (! -d $list ); close (FILE); } if ($Ignores==1) { print "Copy file to $tmpdir/filedir. are you sure? (Y/N) "; my $tmp = ; chomp($tmp); exit (1) if ($tmp eq "N" or $tmp eq "n"); } #copy file from local host to tmpdir print "Copy file from local host to tmpdir...
"; open(FILE,"/$usrtmp/filelist") || die "can not open filelist:$!"; while($filename=) { chomp($filename); # my $bar=`dirname $filename`; # system("mkdir -p $filedir$bar"); system("$rsync_cmd $filename $filedir"); } #Creating addfilelist delfilelist and updatefilelist print "Creating file list .....
"; system("ls -1 $filedir >$tmpdir/filedirlist"); foreach $dirlist (`cat $tmpdir/filedirlist`) { chomp($dirlist); system("$rsync_del $filedir/$dirlist/ root@$host:/$dirlist/|grep "^deleting" |grep -v "^deleting directory"|perl -pi -e 's!deleting !/$dirlist/!'|sort |uniq >>$tmpdir/delfilelist"); system("$rsync_del root@$host:/$dirlist/ $filedir/$dirlist/|grep "^deleting" |grep -v "^deleting directory"|perl -pi -e 's!^deleting !/$dirlist/!'|sort |uniq >>$tmpdir/addfilelist"); system("$rsync_exist $filedir/$dirlist/ root@$host:/$dirlist/|grep -v "^deleting" |grep -v "^skipping"|grep -v "^building" |grep -v "^sent" |grep -v "^total" |grep -v "^wrote "|perl -pi -e 's!->.*!!'|perl -pi -e 's!^receiving *!!'|sort |uniq >>$tmpdir/up"); foreach $update (`cat $tmpdir/up`) { open (FILE, ">>$tmpdir/updatefilelist"); print FILE "/$dirlist/$update"; close (FILE); } } #check file list print "checking delete file list....
"; &checkfilelist("delfilelist"); #copy new file to $usrtmp/filedir &checknotexist("addfilelist"); if (-e "$usrtmp/addfilelist") { print "copy new file to $usrtmp/filedir...
"; &cpfile($usrtmp,"addfilelist"); } #copy update file to $usrtmp/filedir &checknotexist("updatefilelist"); if (-e "$usrtmp/updatefilelist") { print "copy update file to $usrtmp/filedir...
"; &cpfile($usrtmp,"updatefilelist"); } #please running instsutff.pl print "Copy file $inststuff from localhost to $tmpdir @ $host.....
"; system("ssh $host -l root '. /etc/.profile;mkdir $tmpdir'"); system("$rsync -av $inststuff $usrtmp"); system("$rsync -apzq --partial -e $ssh $usrtmp/ root@$host:$tmpdir"); print("************************************************************** **** New files ready for final installation on $host:$tmpdir **** NOW login to $host and running $tmpdir/instsutff.pl **** For example: **** sudo $tmpdir/inststuff.pl -d $tmpdir **************************************************************
"); &cleanup; } &main
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8225414/viewspace-965598/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- (轉)開源IT監控系統對比
- ubuntu與centos系統對比UbuntuCentOS
- 對比ubuntu與centos系統 UbuntuCentOS
- 作業系統比對指令碼[inststuff.pl](轉)作業系統指令碼
- Linux系統和Windows系統對比?哪個更好?LinuxWindows
- Linux系統命令與Solaris系統命令的對比Linux
- 分散式檔案系統(HDFS)與 linux系統檔案系統 對比分散式Linux
- 分散式跟蹤系統——產品對比分散式
- Android與 IOS系統的效能對比AndroidiOS
- 8 種 NoSQL 資料庫系統對比SQL資料庫
- 8種NoSQL資料庫系統對比SQL資料庫
- Linux對戰Windows系統:桌面多圖大對比LinuxWindows
- Linux下常見檔案系統對比Linux
- 推薦系統: 相關推薦方法對比
- 星外主機管理系統與ZKEYS公有云管理系統對比
- Kotlin 對比 轉化Kotlin
- Windows和Linux系統對比,哪個先進?WindowsLinux
- 大資料儲存系統對比:Ceph VS Gluster大資料
- Linux與其他系統對比,具有哪些特點?Linux
- IDC主機系統詳細對比評測
- 監控系統:深度對比Zabbix、Nagios、Pandora FMSiOS
- win10系統系統無法關閉高對比度怎麼辦Win10
- 系統登入認證流程對比(cookie方式與jwt)CookieJWT
- ERP系統的三種遷移模式之對比模式
- Linux和Windows系統對比,哪個更加先進?LinuxWindows
- ERP系統型別大對比,切勿盲目選擇型別
- Win10系統如何關閉高對比度式Win10
- 對比C++和Java (轉)C++Java
- 我對"系統=流程+表單"的看法 (轉)
- 轉載.Linux三大檔案系統比較Linux
- 六大UNIX作業系統的比較(轉)作業系統
- 常見開源分散式檔案系統架構對比分散式架構
- 面向不同需求的物件儲存系統對比:Ceph與Swift物件Swift
- 不同規劃企業對CRM系統的價效比要求
- Memcache,Redis,MongoDB(資料快取系統)方案對比與分析RedisMongoDB快取
- Java陣列轉列表方式對比Java陣列
- 實時作業系統與通用作業系統的一些比較 (轉)作業系統
- 用GHOST對LINUX系統做備份(轉)Linux