HPE GreenLake Administration
- Community Home
 - >
 - Servers and Operating Systems
 - >
 - Operating Systems
 - >
 - Operating System - Linux
 - >
 - Macro definitions in m4
 
Operating System - Linux
        1840126
        Members
    
    
        4924
        Online
    
    
        110161
        Solutions
    
Forums
        Categories
Company
Local Language
                
                  
                  back
                
        
                
        
                
        
                
        
        
        
                
        
                
        
        
        
                
        
              
              Forums
Discussions
Forums
- Data Protection and Retention
 - Entry Storage Systems
 - Legacy
 - Midrange and Enterprise Storage
 - Storage Networking
 - HPE Nimble Storage
 
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
                
                  
                  back
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
            
                
            
                
            
                
            
                
            
            
                
            
                
            
            
                
            
                
              
            Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
 - Appliance Servers
 - Alpha Servers
 - BackOffice Products
 - Internet Products
 - HPE 9000 and HPE e3000 Servers
 - Networking
 - Netservers
 - Secure OS Software for Linux
 - Server Management (Insight Manager 7)
 - Windows Server 2003
 - Operating System - Tru64 Unix
 - ProLiant Deployment and Provisioning
 - Linux-Based Community / Regional
 - Microsoft System Center Integration
 
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
        Information
        Community
Resources
Community Language
        Language
        Forums
Blogs
Topic Options
			
				
					
	
			
		
	- Subscribe to RSS Feed
 - Mark Topic as New
 - Mark Topic as Read
 - Float this Topic for Current User
 - Bookmark
 - Subscribe
 - Printer Friendly Page
 
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
02-27-2006 04:44 AM
02-27-2006 04:44 AM
			
				
					
						
							Macro definitions in m4
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						Hello,
  
I haven't done any m4 scripting before.
Nevertheless, I have been presumptuous enough
to believe that it only takes a little read of the m4 manpage to get me going.
 
Not quite...
 
 
Though this is excercised on a Linux Heartbeat cluster which serves an Apache I think it isn't really OS specific and equally applies to m4 on HP-UX.
  
I simply want to define an IP based virtual host container that should bind its listening socket to the current node's IP address.
Thus I thought this could easily be placed in an m4 template which is to be parsed by m4 through the Heartbeat Apache resource start/stop script right before it fires up the webserver, in order to produce that virtual host container with the fitting IP address.
 
You might ask what this is good for.
The productive webserver has its fixed IP address that travels together with the package
(the same as ServiceGuard's relocative IP).
This additional webserver is only required for maintenance of the cluster nodes.
E.g. I mirrored a MiniCPAN (abt. 400MB) which I want to have serviced by the virtual host
in case should immediate installation of additional CPAN modules be required on the cluster nodes.
 
Ok, here's the m4 mess I have started with,
but somehow I think I haven't apprehended the notion of m4 yet.
I thought it should be possible to simply assign a "macro", very much like a variable in any scripting language, only to be referrenced later.
But this doesn't work in my definition of get_ip.
You see, I don't want to repeat the long parsing command to retreive the IP address everywhere in situ where it is required.
 
When I have run this through m4
  
  
 
# cat vhosts.conf.mc
define(`get_ip' , /sbin/ifconfig eth0|awk -F: '$1~/inet addr/{print$2}'|tr -cd '[0-9.]')
ServerName syscmd(/sbin/ifconfig eth0|awk -F: '$1~/inet addr/{print$2}'|tr -cd '[0-9.]'):ifdef(`PO
RT', `PORT', 80)
ServerAdmin root@syscmd(/sbin/ifconfig eth0|awk -F: '$1~/inet addr/{print$2}'|tr -cd '[0-9.]')
 
  
then this is what I get
 
  
# m4 -DPORT=443 vhosts.conf.mc
  
 :443>
ServerName 192.168.2.2:443
ServerAdmin root@192.168.2.2
 
 
So how do m4 definitions are applied correctly?
 
Regards
Ralph
					
				
			
			
				
		
		
	
	
	
I haven't done any m4 scripting before.
Nevertheless, I have been presumptuous enough
to believe that it only takes a little read of the m4 manpage to get me going.
Not quite...
Though this is excercised on a Linux Heartbeat cluster which serves an Apache I think it isn't really OS specific and equally applies to m4 on HP-UX.
I simply want to define an IP based virtual host container that should bind its listening socket to the current node's IP address.
Thus I thought this could easily be placed in an m4 template which is to be parsed by m4 through the Heartbeat Apache resource start/stop script right before it fires up the webserver, in order to produce that virtual host container with the fitting IP address.
You might ask what this is good for.
The productive webserver has its fixed IP address that travels together with the package
(the same as ServiceGuard's relocative IP).
This additional webserver is only required for maintenance of the cluster nodes.
E.g. I mirrored a MiniCPAN (abt. 400MB) which I want to have serviced by the virtual host
in case should immediate installation of additional CPAN modules be required on the cluster nodes.
Ok, here's the m4 mess I have started with,
but somehow I think I haven't apprehended the notion of m4 yet.
I thought it should be possible to simply assign a "macro", very much like a variable in any scripting language, only to be referrenced later.
But this doesn't work in my definition of get_ip.
You see, I don't want to repeat the long parsing command to retreive the IP address everywhere in situ where it is required.
When I have run this through m4
# cat vhosts.conf.mc
define(`get_ip' , /sbin/ifconfig eth0|awk -F: '$1~/inet addr/{print$2}'|tr -cd '[0-9.]')
ServerName syscmd(/sbin/ifconfig eth0|awk -F: '$1~/inet addr/{print$2}'|tr -cd '[0-9.]'):ifdef(`PO
RT', `PORT', 80)
ServerAdmin root@syscmd(/sbin/ifconfig eth0|awk -F: '$1~/inet addr/{print$2}'|tr -cd '[0-9.]')
then this is what I get
# m4 -DPORT=443 vhosts.conf.mc
ServerName 192.168.2.2:443
ServerAdmin root@192.168.2.2
So how do m4 definitions are applied correctly?
Regards
Ralph
	Madness, thy name is system administration
			
			
				
			
			
			
			
			
			
		- Tags:
 - m4
 
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
		
	
	
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP