Forum Discussion

RiverFish's avatar
RiverFish
Icon for Altostratus rankAltostratus
May 04, 2015

Script that generates tmsh commands

I found the following awesome command on devcentral that creates a file named commands.sh that contains all of the tmsh commands needed to modify the 3rd octet of every VIP on the unit:

echo '!/bin/bash' > /shared/commands.sh; tmsh list ltm virtual destination | tr '\n' ' ' | sed 's/ \+/ /g;s/ltm virtual/\ntmsh modify ltm virtual/g;s/nation 10\.23\.206/nation 10.23.207/g' >> /shared/commands.sh; chmod 755 /shared/commands.sh

What I need is a much simpler version of this command that will create a file named commands.sh that contains all of the tmsh commands needed to re-create all of the nodes on an existing unit, on a brand new unit. So the result would be:

tmsh create ltm node address tmsh create ltm node address tmsh create ltm node address etc...

I know there are easier ways to do this, like copying the node portion of the existing config and pasting it into the new config, but I have my reasons for wanting to do it the above way that I won't go into. Any help is much appreciated.

  • Correction:

     

    So the result would be:

     

    tmsh create ltm node address

     

    tmsh create ltm node address

     

    tmsh create ltm node address

     

    etc...

     

  • ugh! Why can't I edit my post? I click save and nothing happens.

     

  • So the result would be:

    tmsh create ltm node  address    
    tmsh create ltm node  address    
    tmsh create ltm node  address    
    etc... 
    
  • tmsh list ltm node | tr '\n' ' ' | sed 's/ \+/ /g;s/{//g;s/}//g;s/ltm node/\ntmsh create ltm node/g' >> create_nodes.sh

  • !/bin/bash
    
    echo " Create and configure Nodes "
    echo ""
    echo " Suppresion d'un node"
    tmsh delete ltm node N1-HTTP
    tmsh delete ltm node N1-HTTP
    
    echo "Create Nodes with default Monitor"
    tmsh create ltm node N1-HTTP address @IP-NODE1 monitor default
    tmsh create ltm node N2-HTTP address @IP-NODE2 monitor default
    
    echo "Suppresion d'un node"
    tmsh delete ltm node N3-HTTP
    
    echo "Create node with HTTPS Monitor"
    tmsh create ltm node N3-HTTP description Node HTTPS address @IP-NODE3 monitor https_443
    
    echo "Edit node monitor"
    tmsh modify ltm node N3-HTTP monitor default
    
    echo "Show Node"
    tmsh list ltm node state 
    
    echo "Show Node with metadata ratio session"
    tmsh list ltm node metadata ratio session
    
    echo "Show Node 1 details"
    tmsh list ltm node  N1-HTTP session