RandomUser RandomUser - 6 months ago 9
Linux Question

Passing command as input to diff command in bash

I am trying to compare the file system states of a server, and I am storing the benchmark (initial state) in one

initialSnapshot.log
file. And now I am trying to compare it with runtime data , so I can echo any change in file stats.

#Capture the filesystem stats at the start and store them in initialSnapShot.log file.

find storage1 -type f -ls > initialSnapShot.log

#While loop to keep continues check on stats.

while true
do
#Below command does not work
diff --suppress-common-lines -y `find storage1 -type f -ls` initialSnapShot.log


done


However, it does not work as per plan

diff: invalid option -- -
diff: Try `diff --help' for more information.


Please suggest any better design approach ? Shall I store the output of find inside second file(Seems dirty) ?

Edit:

find storage1 -type f -ls
3366871 439652 -rw-rw-r-- 1 randomUser random 449314816 Jun 8 07:47 storage1/bla1
3366884 0 -rw-rw-r-- 1 randomUser random 0 Jun 9 04:29 storage1/blass
4639952 0 -rw-rw-r-- 1 randomUser random 0 Jun 9 04:44 storage1/blass222122
4639950 0 -rw-rw-r-- 1 randomUser random 0 Jun 9 04:33 storage1/blass2221
4639951 0 -rw-rw-r-- 1 randomUser random 0 Jun 9 04:33 storage1/blass22212
4639953 0 -rw-rw-r-- 1 randomUser random 0 Jun 9 04:45 storage1/blass2221221
4639954 0 -rw-rw-r-- 1 randomUser random 0 Jun 9 04:47 storage1/blass22212211
4639955 0 -rw-rw-r-- 1 randomUser random 0 Jun 9 04:47 storage1/blass2221221121

Answer

Are you using bash? If so, try using bash process substitution:

diff --suppress-common-lines -y <(find storage1 -type f -ls) initialSnapShot.log

Or, if you're not using bash, try specifying it explicitly

bash -c 'diff --suppress-common-lines -y <(find storage1 -type f -ls) initialSnapShot.log'