I have log files on two directories, for simplicty I'm going to call then dir 1 and dir 2.
Let's say the user enters file.log which is located in dir1, I should tail -f all files from dir1 and dir2 except file.log. Can somebody help me with this please.
ssh host 'find /path/to/a/log -maxdepth 1 -type f -name "file*" -name "*.log" ! -name "$1" -print0 -exec tail {} \;' > /home/pl-${node}.log
ssh host 'find /path/to/a/log -maxdepth 1 -type f -name "file*" -name "*.out" ! -name "$1" -print0 -exec tail {} \;' > /home/pl-${node}.out
node is just a variable that stores 1 and 2. when i enter ./test file-1.log, the output is:
pl-1.log
Oct 21 09:15 pl-1.out
Oct 21 09:15 pl-2.log
Oct 21 09:15 pl-2.out
As you see all files were tailed, even though i specified file-1.log to not be tailed in argument $1
.
Something like this should make it:
find . -type f ! -name "*dir1/file.log" -exec tail {} \;
That is, use find ... -exec tail {} \;
adding the extra condition that the file does not have to be named as file.log
.
how can i use find if the name of the file is an argument in the command line.for example find . ! -type f -name "$1"
Like this, for example:
ssh host "find /path/to/a/log -maxdepth 1 -type f -name 'file*.log' ! -name \"$1\" -print0 -exec tail {} \;" > /home/pl-${node}.out
Note that I am using find ".... -name \"$1\" ... "
because to "send" variables you need double quotes.