How to catch and handle Makefile exceptions

Thread Tools Search this Thread
Operating Systems Solaris How to catch and handle Makefile exceptions
# 1  
Old 12-14-2007
How to catch and handle Makefile exceptions

I have a simple makefile which I use to sync libraries files from /source/sybase directory on the source machine where the Makefile resides to /destination/folder on the various destination machines like machine1, machine2, machine3 using solaris utility 'rsync'. So when I run "make -f makefilename synclibraries", the sync goes through fine on all the machines. However if one of the machines (eg: machine2) is down, then makefile aborts midway because rsync fails and skips the sync on all the subsequent machines. Is there a way to capture the rsync error inside the Makefile and skip those machines which are down and proceed with syncing the subsequent machines ? If so how can I modify the below Makefile code. This would be really helpful because in future I would be expanding this makefile to handle 100s' of machines and it would be hard to track and rerun, if Make aborts midway due to an issue with any of those machines

MACHINELIST = loginname@machine1 \
loginname@machine2 \
loginname@machine3 \

synclibraries :
for target in $(MACHINELIST); do /usr/local/bin/rsync -avb --suffix .bk -e 'ssh -x' -n /source/sybase $$target:/destination/folder; done

Your help/suggestions would be greatly appreciated

# 2  
Old 12-14-2007
1. I know you have made the investment in using make but is this the correct tool for the job?

2. Split up the makefile into separate make file tasks, so that each makefile is a task that should complete together.

3. have a script that runs the make files tasks and logs the errors.
# 3  
Old 12-14-2007
I know the error the Makefile is reporting. For example if machine1 has some connection issues then rsync cannot connect to machine1 and returns error. As a result Makefile aborts with fatal error instead of trying to run rsync on the next host which is machine2. See the Error output below. So how could I have the Makefile continue syncing machine2, machine3, machine4 etc. instead of just aborting. Its easy to remove the offending hostname from the makefile and rerun when the number of hosts is small like here. But when we have over 100 machines, the Makefile runs for several hours and to keep waiting for it to fail on some machine somewhere in the middle and then manually fix the makefile and rerun gets tedious. So and self correcting mechanism within the makefile to catch these errors and skip these erroneous hosts and proceed to the next machine in the list would be automated and convenient. Is there any way of achieving this ?
See Error output below when machine1 is the offending UNIX box.

for target in loginname@machine1 loginname@machine2 loginname@machine3; do /usr/local/bin/rsync -avb --suffix .bk -e 'ssh -x' -n /source/sybase $target:/destination/folder; done
warning: Connecting to machine1 failed: No address associated to the name
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(359)
*** Error code 12
make: Fatal error: Command failed for target `scsmerllistsync'

# 4  
Old 12-14-2007
Originally Posted by waavman
So how could I have the Makefile continue syncing machine2, machine3, machine4 etc. instead of just aborting.
By having them as separate make targets (rules sets) and using a script that calls make on the outside and does not stop depending on the return code.

for machine in mach1 mach2 mach3
     if make -f make.mak $machine
             echo $machine synced
             echo 1>$2 $machine failed

The idea with make is it's supposed to stop when a target cannot be made.
# 5  
Old 12-15-2007
thanks Porter. let me try tinkering the makefile like that and see how it goes.
# 6  
Old 12-18-2007
The script mechanism works fine when one of the machines is completely down and does not have an IP address as rsync/ssh to that machine returns an error and so make terminates and make -f make.mak $machine returns an error code. However if the target machine has a corrupt drive or some similar issue, rsync/ ssh to that machine does not return error. Instead it hangs trying to connect to that machine
So when I run
if make -f make.mak $machine as you suggested below,
if a particular $machine has a corrupt drive, then rsync within the makefile just hangs trying to connect to that machine just as ssh to such a machine would hang without returning and error code. As a result the script calling the makefile hangs at the if clause ( if make -f make.mak $machine ) without proceeding to the next statement in the script. Is there a way I can signal an error when make -f make.mak $machine does not return after a while for any machine since it is not able to rsync / ssh to $machine due to issues such as corrupt drive etc. ?

# 7  
Old 12-18-2007
Originally Posted by waavman
Is there a way I can signal an error when make -f make.mak $machine does not return after a while for any machine since it is not able to rsync / ssh to $machine due to issues such as corrupt drive etc. ?
The question of course is how would you know it's hanging due to a severe failure rather than just a busy network or busy server?

One possible solution is to run sleep in parallel but it starts getting messy very quickly trying to synchronise the various completion options. A solution would be to develop a generic timeout script that can run any command with a timeout. But you do need to solve the question regarding how do you know its failing?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

RegEx with exceptions

I am totaly new to RegEx, but I need to extract emails with RegEx from text file Some difficulties: 1. “@”symbol has been substituted for “ at ”,"AT" or "(at)" 2. I do not need any email with domain "myoldcompany" I found that with these I can found any emails: "^+@+\.+$" How to do... (1 Reply)
Discussion started by: AIX_30
1 Replies

2. Shell Programming and Scripting

Wildcards and exceptions

Hello: I have a very basic question. I'd like to select all files except for one file. For example, say I want to move all of the files in my current directory to a subdirectory called archive, I would use mv ./* archive/ But what if I want to move all files except for README.txt? Is there an... (19 Replies)
Discussion started by: Danny.Boy
19 Replies

3. Programming

Relationship between exceptions and signals

Hi everyone, I am using AIX 6.1. There are exception codes defined in header file sys/m_except.hAlso, in the documentation (in "Understanding exception handling") it says: If no exception handler is currently defined when an exception occurs, typically one of two things happens. If... (0 Replies)
Discussion started by: manolo123
0 Replies

4. UNIX for Dummies Questions & Answers

Diff with exceptions Question

So I'm currently developing an automated test system and I'm verifying my results by running a set of baselined data through and comparing the output (which is in a txt file) to a baseline results file. So of course I'm just using the diff command. Unfortunately each time I run the test there are 2... (3 Replies)
Discussion started by: Smitty0881
3 Replies

5. UNIX for Dummies Questions & Answers

Difference between handle to the thread HANDLE and thread identifier pthread_t

This question might be silly but its confusing me a bit: What is the difference between handle to the thread HANDLE and thread identifier pthread_t? ---------- Post updated at 01:52 PM ---------- Previous update was at 01:48 PM ---------- Sorry I saw details and HANDLE is in windows and... (0 Replies)
Discussion started by: rupeshkp728
0 Replies

6. Homework & Coursework Questions

Help with Simple Multi-Level Makefile (Extremely New at Makefile)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Basically, the prompt is make a makefile with various sub makefiles in their respective subdirectories. All code... (1 Reply)
Discussion started by: Tatl
1 Replies

7. Shell Programming and Scripting

How to handle exceptions in "nawk -F"

Suppose the nawk -f doesnot work due to some reasons ,in such a case how to handle the exceptions or the error messages nawk -f "|" 'NR==FNR{a .......} ..print{ $0} file_1.txt file_2.txt > file_3.txt suppose due to a syntax error the command doesnot work then can we catch the error... (1 Reply)
Discussion started by: centurion_13
1 Replies

8. Programming

how to handle SQL exceptions to call script having args via java ?

Hi, i want to call shell script via java + in that shell script i m doing some sql operation by connecting to sqlplus . i want to return 0 if successful exeution of SQL operations else 1 ; is it possible ? #!/bin/sh Name=$1; export ORACLE_HOME $ORACLE_HOME/bin/sqlplus... (3 Replies)
Discussion started by: crackthehit007
3 Replies

9. UNIX for Advanced & Expert Users

Makefile problem - How to run module load in a Makefile

Hi, I'm trying to run the module load command in a Makefile and i'm getting the following error: make: module: command not found Why is this? Is there any way to run this command in a Makefile? NOTE: command - module load msjava/sunjdk/1.5.0 works fine outside of the Makefile (2 Replies)
Discussion started by: hernandinho
2 Replies

10. Shell Programming and Scripting

exceptions in import

Hello, I want to import an Oracle database file on my fresh DB, bought before successfully with exp command. But is it possible to import some tables from the dmp file, because they are too large and it's so long !? I didn't find any option in imp command to make exception on certain tables...... (1 Reply)
Discussion started by: madmat
1 Replies
Login or Register to Ask a Question