Solaris Tip: Have Your Files Changed Since Installation?

By  

Both files have the same permissions and owners/groups that they had when installed.

# ls -l /usr/bin/date
-r-xr-xr-x   1 root     bin        11056 Jan 22  2005 /usr/bin/date
# grep /usr/bin/date /var/sadm/install/contents
/usr/bin/date f none 0555 root bin 11056 63512 1106444884 SUNWcsu

# ls -l /etc/inet/hosts
-r--r--r--   1 root     sys          302 Dec 30  2008 /etc/inet/hosts
# grep /etc/inet/hosts /var/sadm/install/contents
/etc/inet/hosts e hosts 0444 root sys 61 4625 1204210814 SUNWcsr

The pkgchk command with the -l and -p options can be used to check information on individual files.

# pkgchk -l -p /usr/bin/date
Pathname: /usr/bin/date
Type: regular file
Expected mode: 0555
Expected owner: root
Expected group: bin
Expected file size (bytes): 11056
Expected sum(1) of contents: 63512
Expected last modification: Jan 22 20:48:04 2005
Referenced by the following packages:
        SUNWcsu
Current status: installed

Using a simple grep command, you can pull the same information from the contents file in a more terse (non-tagged) format. Notice that the time stamp associated with the file is displayed in the internal (Unix time) format in the contents file record shown below.

# grep /usr/bin/date /var/sadm/install/contents
/usr/bin/date f none 0555 root bin 11056 63512 1106444884 SUNWcsu

This grep command, for example, displays details on the /usr/bin/date file as it was installed. For files that are expected to change in size, the information displayed by pkgchk omits some of this information. Here, for example, is what it shows for the hosts file. Notice
that no date or sum values are displayed:

# pkgchk -l -p /etc/inet/hosts
Pathname: /etc/inet/hosts
Type: editted file
Expected mode: 0444
Expected owner: root
Expected group: sys
Referenced by the following packages:
        SUNWcsr
Current status: installed

We can use the sum command to determine whether the sum associated with a file matches that recorded when the file was first installed. You can also verify the file's permissions (or "mode"), the owner and group.

If you want to automate checking individual files, you can use a script like that shown below. Let me explain some of the possibly non-obvious commands.

1) The while statement following the first if command will keep looping until a full pathname is typed and exit if the specified file doesn't exist. The pkgchk command needs a full path whether or not the command in question is on the user's search path.

2) Following the while loop, we grab the first five attributes of the target file (mode, number of links, etc.) and stuff them into obvious variable names.

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Spotlight on ...
Online Training

    Upgrade your skills and earn higher pay

    Readers to share their best tips for maximizing training dollars and getting the most out self-directed learning. Here’s what they said.

     

    Learn more

Operating SystemsWhite Papers & Webcasts

See more White Papers | Webcasts

Answers - Powered by ITworld

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Ask a Question
randomness