Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Obtaining null value from FIND command. 1

Status
Not open for further replies.

AnotherAlan

Technical User
Feb 10, 2006
362
GB
Hi All,

I'll try and explain this as best I can.
I have written this;
ssh -n $h "/bin/test -d $core2 && find $core2 -mtime -1"

This finds all core dumps from the previous 24 hours. (Well I hope it does)
What I would like to achieve is finding a way to check if this returns a null value. i.e. There were no core files for that particular host.
I've toyed with the idea of assigning the ssh command to a variable...this works but is not great, it prints all to one line and then I have to mess around with awk to seperate.

My understanding is that unlike grep, find always returns a $?=0.

I'm a bit stumped. All suggestions to eliminate the variable|awk route most welcome.

Thanks
Alan

 
Hi

Alan said:
I've toyed with the idea of assigning the ssh command to a variable...this works but is not great, it prints all to one line and then I have to mess around with awk to seperate.
Why to mess around with [tt]awk[/tt] if you want to know only if it returned something or not ?
Code:
test "$( ssh -n $h "/bin/test -d $core2 && find $core2 -mtime -1" )" || echo "found nothing"

Feherke.
 
Feherke,

This is why I like this forum.
Good answers fast. Thanks a lot, have a star.
I guess I was overlooking the obvious and trying to be smarter than I am.

Much appreciated.
Alan
 
Feherke, can I bother you some more?

The test condition works great, but I would like to have the results of find printed / listed to a file, if no results then print "found nothing".

I have played with the syntax you offered but can't make it work.

Here is the situation.
I have a list of servers to check.
I have these in a file called within a loop.
The ssh line goes to check for the existence of the core files, if they are there then they are appended to a seperate file, if they are not there the output is still appended to the file. I would like to remove the blank entries...hence the test for a null variable.

My script is;
for h in `cat $serverlist`

do
echo "_______________________________________"
echo "$h-$today"
echo "---------------------------------------"
ssh -n $h "/bin/test -d $core2 && find $core2 -mtime -1;/bin/test -d $core1 && find $core1 -mtime -1"
echo "---------------------------------------"
done | tee $outfile

And thanks again for helping me out.
Alan

 
Hi

Now I am abit confused. I think this is what you need :
Code:
while read h; do
  echo "_______________________________________"
  echo "$h-$today"
  echo "---------------------------------------"
   
  res="$( [gray]ssh -n $h "/bin/test -d $core2 && find $core2 -mtime -1;/bin/test -d $core1 && find $core1 -mtime -1"[/gray] )"
  echo "${res:-found nothing}"

  echo "---------------------------------------"
done < "$serverlist" | tee "$outfile"

Feherke.
 
Feherke,

Works brilliantly, thanks very much for your help.
Always appreciated.

Alan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top