Reputation: 45
So I am trying to make a script to call the timestamps from repo files to compare them between environments to see if they have been synced within a certain amount of time these are the two commands I have.
$echo;
for environment in dev test production; do
echo "${environment}"
ls -la /opt/maintenance/repos/epel/"${environment}"/*/x86_64/repodata/*filelists.sqlite.bz2
echo -e '\n'
done
This pulls the files I need to compare for the different environments (test, dev, production).
now how would I "pipe" or enter these files into this snippet to compare the timestamps
file1=$(stat -c %Y .bash_profile)
file2=$(stat -c %Y .bashrc)
date_diff=$((( ${file1} - ${file2})/86400 ))
echo "${date_diff}"
I was thinking originally to pipe the output of the first command onto an array and then having that be how the second command calls it. Am I thinking this through correctly?
Upvotes: 1
Views: 99
Reputation: 189377
This contains a fair amount of guesswork, but perhaps you are looking for
stat -c '%Y %n' /opt/maintenance/repos/epel/{dev,test,production}/*/x86_64/repodata/*filelists.sqlite.bz2
The output should be easy to pass to Awk to compare the first field on each line and possibly print in some human-readable form. If you want to compare each subsequent one against the first, maybe pipe to
... | awk 'NR==1 { age=$1; next }
{ $1 = ($1-age) / 86400; print }'
The brace expansion {dev,test,production}
is a Bash feature which is not portable to other shells. The stat
options you used aren't portable either so it looks like you are on Linux anyhow.
Upvotes: 1