# Create LTM Virtuals

**URL:** <https://community.f5.com/t/create-ltm-virtuals/64770>\
**Category:** Community CodeShare\
**Tags:** tmsh, ltm, application-delivery\
**Created:** [March 10, 2015, 7:01pm UTC](https://community.f5.com/t/create-ltm-virtuals/64770 "2015-03-10T19:01:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![CodeCentral\_194](https://avatars.discourse-cdn.com/v4/letter/c/c77e96/32.png) [@CodeCentral\_194](https://community.f5.com/u/CodeCentral_194)\
**Post date:** [March 10, 2015, 7:01pm UTC](https://community.f5.com/t/create-ltm-virtuals/64770/1 "2015-03-10T19:01:37Z")

</div>

**Problem this snippet solves:**

This example shows how to automate virtual server creation with tmsh scripting.

**How to use this snippet:**

Note: This was used in conjunction with a simple iRule just to create HTTP responders for another LTM system. The iRule is very simple:

```auto
when HTTP_REQUEST {
  HTTP::respond 200 content "

```

[IP::local\_addr]" }

**Code :**

```auto
cli script create_virtuals.tcl {

proc script::run {} {
    if { $tmsh::argc < 4 } {
       puts "Requires three arguments: <first virtual=""> <count> <irule>"
       exit
   } else {
       set start [lindex $tmsh::argv 1]
       set total [lindex $tmsh::argv 2]
       set rulename [lindex $tmsh::argv 3]
   }
   scan $start "%d.%d.%d.%d:%d" a b c d p
   for {set x 0} {$x < $total} {incr x} {
       tmsh::create ltm virtual testvip_$x destination $a.$b.$c.$d:$p profiles add \{http\} rules \{$rulename\}
       incr d
       if { $d > 255 } {
           set d 0
           incr c
           if { $c > 255 } {
               set c 0
               incr b
               if { $b > 255 } {
                   set b 0
                   incr a
               }
           }
       }
    }
}

proc script::help {} {
    tmsh::add_help "Create contiguous block of virtual servers as HTTP responders\n\
       <first virtual=""> <count> <irule>" 
}

}</irule></count></first></irule></count></first>

```
