UFS Automate tar /dev/null for integrity checking

gofer_touch

Well-Known Member

Reaction score: 126
Messages: 252

I am running a couple of FreeBSD systems using UFS and am interested in learning whether it is possible to print the results of a tar operation to a text file?

Ultimately what I am trying to do is create an ad-hoc file system integrity checking system. This would be done by creating cron jobs which systematically tar mounts to /dev/null and then have it print any error messages to dated text files that can be read when and as needed.

Has anyone done anything similar to this?
 

usdmatt

Daemon

Reaction score: 514
Messages: 1,382

You mean the cron job is going to tar the contents of a mount to /dev/null?
Either way, you should be able to capture STDOUT & STDERR from tar using a shell script along the lines of the below. (assuming I understand correctly that you just want to capture any output of tar, so you can view it later)

Code:
#!/bin/sh

JOB_TIME=$(date +"%Y%m%d-%H%M%S")

/usr/bin/tar [tar options] >"/log/path/check-${JOB_TIME}.log" 2>&1
(Edit: changed the names in example - it's obviously not a backup going to /dev/null....)
 
OP
OP
gofer_touch

gofer_touch

Well-Known Member

Reaction score: 126
Messages: 252

Thanks usdmatt, this is what I was seeking, although I was hoping for just a one line command that could be added to a cron instead of the creation of a script and then calling it thereafter. But this could work nicely. I'll give it a try.
 

usdmatt

Daemon

Reaction score: 514
Messages: 1,382

It could possibly be crammed into a single line in crontab but I think it would be an ugly way of doing it (Could just be me though). To me it makes more sense to have a small script that can be re-used, possibly even with additional error reporting -

Code:
integrity-check.sh /usr
Code:
#!/bin/sh

HOST=$(hostname)
JOB_TIME=$(date +"%Y%m%d-%H%M%S")
JOB_TARGET=$1

if [ -z "${JOB_TARGET}" ]; then
  echo "Usage: $0 path"
  exit 1
fi

echo "-- Integrity Output for mount point ${JOB_TARGET} --" > "/logs/job-${JOB_TIME}.log"
tar [tar options] "${JOB_TARGET}" >>"/logs/job-${JOB_TIME}.log" 2>&1

# send email if tar actually failed, prompting user to check the log
if [ $? -ne 0 ]; then
    echo "Integrity check exited with error $? for ${HOST}:${JOB_TARGET}" | mail -s "Integrity Check Failed" me@mydomain.com
fi
 
OP
OP
gofer_touch

gofer_touch

Well-Known Member

Reaction score: 126
Messages: 252

Thanks! I think I'll snip this one from you and give it a go. Additional features are nice too!
 

chrbr

Aspiring Daemon

Reaction score: 240
Messages: 670

From time to I use find * -type f -exec sha256 -r {} \; and output the result to a text file. Some post processing helps to find dupes of files in my PDF collection. Initially I have had the idea to apply this method as some kind of an integrity check on UFS.
 
Top