Linux比较两台机器上的软件包是否一致

代码:

#!/usr/bin/awk -f# dpkg-diff.awk – compare and print differencies in the installed packages of two dpkg status files# by xmb – localhack# xmb@skilled.com# 19.11.2003, 23.01.2005(do_ver,status->4)# status in the array:# 1 = installed in the reference file, but not in the other one# 2 = both matching# 3 = newly intsalled on the other status file# 4 = version change# decided to use additionally a plain index for faster processing of the END blockBEGIN {if (! status) status = “/var/lib/dpkg/status”if (! do_ver && do_ver != “0”) do_ver = 1 # version comparingif (ARGC <= 1 && ! stdin) {print “Usage: dpkg-diff.awk [-v status=reference-status-file] <-v stdin=1|other status file>”print “By default, /var/lib/dpkg/status is used as reference”print “use -v stdin=1 to pipe instead of specify a file (like /var/backups .gz ones)”print “you may also specify only one non reference status file”exit 1}if (stdin)ARGC = 1elseARGC = 2while (getline < status) {if ($1 == “Package:”) {tmp = $2getline < statusif ($1 != “Status:”)getline < statusif (! /install ok/)continueif (do_ver == 1)ver = get_ver(status)Package[tmp] = 1#if (ver) { Package[tmp, v] = ver; ver = “” }if (do_ver == 1) Package[tmp, v] = veridx = idx tmp ” “}} close(status)}$1 == “Package:” {tmp = $2getlineif ($1 != “Status:”)getlineif (/install ok/) {if (Package[tmp]) {if (do_ver == 1) {ver = get_ver()#if (ver == -1) # ..if (Package[tmp, v] == ver)Package[tmp] = 2else {Package[tmp, “nv”] = verPackage[tmp] = 4}} elsePackage[tmp] = 2} else {Package[tmp] = 3idx = idx tmp ” “}}if (! valid_file)valid_file = 1}END {if (! valid_file) {print “Invalid file specified”exit 1}# ‘iin’ instead of ‘in’ cause ‘in’ is an awk keywordsplit(idx, Idx)while (Idx[++i]) {if (Package[Idx[i]] == 1)Res[1, ++iin] = Idx[i]else if (Package[Idx[i]] == 3)Res[3, ++out] = Idx[i]else if (Package[Idx[i]] == 4)Res[4, ++V] = Idx[i]} iin = out = V = 0while (Res[1, ++iin])printf “+ %s\n”, Res[1, iin]while (Res[3, ++out])printf “- %s\n”, Res[3, out]while (Res[4, ++V])printf “~ %-20s\t%-10s -> %s\n”, Res[4, V], Package[Res[4, V], v], Package[Res[4, V], “nv”]#if (! Res[1, 1] && ! Res[3, 1])if (iin == out == V == 1)print “No differencies found.”}function get_ver(stream ,stop) { # eliminate duplicated getline code.. butwhile (! stop) { # no but, function doneif (stream) getline < streamelse getlineif ($1 == “Version:”)return $2else if (! $1)return -1}}

运行:./dpkg-diff.awk –v status=/var/lib/dpkg/status /path/to/other_dpkg_status

,当你开展的事业从事的行动穷途末路大势已去的时候,

Linux比较两台机器上的软件包是否一致

相关文章:

你感兴趣的文章:

标签云: