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!

Scripting 1

Status
Not open for further replies.

deadbeef

IS-IT--Management
Jul 31, 2001
39
CA
Hi,

I'm trying to log on two seperate file.
In the case of a success i want the result to be log in one file, in the case of a failure i want to log in an other file.

Here is my command:
find My_File \; 1>> /home/My_user/Log1.log 2>> /home/My_user/Log2.log

But it always log in the two files.
What am i doing wrong ?

Ben
 
For starters, your "find" syntax is wrong.

find / My_file > found.out 2> found.err

I'm not quite sure why you'd be interested in the error output, as it's usually due to permissions (current userid not allowed to access particular directories) other than to filter it out (2>/dev/null).
 
Thanks.

I still have a problem.
It always create the two files. But there is one with the result in it and the other one is empty.

The reason why i want to do this is because one server hang for no reason from time to time, so I run a rcp from one server to the other and want to log it to a file only if there is an error (cause we can still ping the server). If there is a connection error on two server, i want to create that file (result of the rcp in ERROR case only) so that my connection script can see it and page the support.

Ben
 
Ok, using "find" isn't going to generate an error in the way it sounds like you want. It doesn't return errors if it doesn't find a particular file, it just returns nothing. I suppose you could pipe the .out file through "wc -l" and test that result for zero, but it'd be easier to do this:

(mix of ksh and pseudocode)
[tt]
#!/bin/ksh

HEARTBEAT=/whereever.your.heartbeat.semaphore.file.is

if test -f ${HEARTBEAT}
then
# Heartbeat is good. Do whatever.
else
# No heartbeat. Page someone
fi
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top