2

In my shell script In need to compare the date creation of the j2re-1.4.2_10-fcs rpm pkg against the date creation of some files and verify if file creation is newer then rpm pkg creation

my question: if someone have a smart idea how to compare file against rpm creation? In order to find if file date is older or newer the rpm date creation

      rpm -qi j2re-1.4.2_10-fcs | grep "Install Date"
      Install Date: Mon 20 Sep 2010 02:01:04 PM IST      Build Host: localhost.localdomain




   ls -ltr /etc/hosts
   -rw-r--r--    1 root     root          563 Sep  7 10:28 /etc/hosts

2 Answers 2

1

Unix doesn't store creation dates, but you can compare modification (or access or change dates).

rpmdate=$(rpm -qi j2re-1.4.2_10-fcs | sed -n '/Install Date/ s/Install Date:\(.*\)Build Host:.*/\1/p')
rpmdate=$(date -d "$d" +%s)
filedate=$(stat --printf=%Y /etc/hosts)
if (( filedate > rpmdate ))
then
    echo "File is newer than RPM"
echo
    echo "File is NOT newer than RPM"
fi
2
  • but I want to compare rpm creation agains file
    – or100
    Sep 21, 2010 at 14:36
  • @or100: Sorry, I misread your question. See my edit. Sep 21, 2010 at 15:43
0

This should work. Fit it to your needs.

#!/bin/bash

rpm_path="$1"
file_path="$2"

file_date_row=`ls -l --time-style=+%Y%m%d $file_path`
file_date=`echo "$file_date_row" | awk -F" " '{print $6}'`

rpm_date_row=`rpm -qi $rpm_path | grep "Install Date"`
rpm_year=`echo "$rpm_date_row" | cut -d " " -f 6`
rpm_month=`echo "$rpm_date_row" | cut -d " " -f 5`
rpm_day=`echo "$rpm_date_row" | cut -d " " -f 4`

case $rpm_month in
   Jan)
   rpm_date="$rpm_year""01""$rpm_day"
   ;;
  Feb)
   rpm_date="$rpm_year""02""$rpm_day"
   ;;
   Mar)
   rpm_date="$rpm_year""03""$rpm_day"
   ;;
   Apr)
   rpm_date="$rpm_year""04""$rpm_day"
   ;;
   May)
   rpm_date="$rpm_year""05""$rpm_day"
   ;;
   Jun)
   rpm_date="$rpm_year""06""$rpm_day"
   ;;
   Jul)
   rpm_date="$rpm_year""07""$rpm_day"
   ;;
   Aug)
   rpm_date="$rpm_year""08""$rpm_day"
   ;;
   Sep)
   rpm_date="$rpm_year""09""$rpm_day"
   ;;
   Oct)
   rpm_date="$rpm_year""10""$rpm_day"
   ;;
   Nov)
   rpm_date="$rpm_year""11""$rpm_day"
   ;;
   Dec)
   rpm_date="$rpm_year""12""$rpm_day"
   ;;
esac

if [[ "$rpm_date" > "$file_date" ]]
then
   echo "The RPM is newer than the file"
elif [[ "$rpm_date" < "$file_date" ]]
then
   echo "The file is newer than the RPM"
else
   echo "The file and the RPM have the same date"
fi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .