{"id":426,"date":"2019-07-08T10:38:20","date_gmt":"2019-07-08T10:38:20","guid":{"rendered":"http:\/\/www.hammerdb.com\/blog\/?p=426"},"modified":"2019-07-08T10:38:33","modified_gmt":"2019-07-08T10:38:33","slug":"running-hammerdbcli-from-a-bash-or-batch-script-updated-for-v3-2","status":"publish","type":"post","link":"https:\/\/www.hammerdb.com\/blog\/uncategorized\/running-hammerdbcli-from-a-bash-or-batch-script-updated-for-v3-2\/","title":{"rendered":"Running hammerdbcli from a bash or batch script updated for v3.2"},"content":{"rendered":"<p>By default the HammerDB command line interface was designed to run interactively. However many people wanted to run it from a script and an example to do this was shown <a href=\"https:\/\/www.hammerdb.com\/blog\/uncategorized\/driving-hammerdbcli-from-a-bash-script\/\">here<\/a>. However this only worked on Linux and therefore @xychar proposed a modification to run command line scripts directly instead of typing commands by hand for Windows, as using pipe for standard input does not work on Windows.<\/p>\n<p>Reviewing the proposed change it was clear that doing the same thing as running an autopilot script in the GUI could be adapted for use with the CLI and therefore from version 3.2 it is possible to add the auto keyword and the same of a script to run it non-interactively, for example hammerdbcli auto script_to_run.tcl&nbsp; on Linux or hammerdbcli.bat auto script_to_run.tcl on Windows.<\/p>\n<p>An example script is shown to build a schema called buildcli.tcl. Note that the line &#8220;vwait forever&#8221; has been added so that the interpreter enters the event loop that happens automatically in interactive mode.<\/p>\n<pre>!\/bin\/tclsh\nputs \"SETTING CONFIGURATION\"\nglobal complete\nproc wait_to_complete {} {\nglobal complete\nset complete [vucomplete]\nif {!$complete} { after 5000 wait_to_complete } else { exit }\n}\ndbset db ora\ndiset connection system_password oracle\ndiset connection instance vulpdb1\ndiset tpcc count_ware 2\ndiset tpcc num_vu 2\ndiset tpcc tpcc_def_tab users\nprint dict\nbuildschema\nwait_to_complete\nvwait forever<\/pre>\n<p>This can then be called as follows from a driving script. The auto keyword then makes hammerdbcli enter a non-interactive mode to run the specified script.<\/p>\n<pre>$ more build.sh\n#!\/bin\/bash\necho \"BASH SCRIPT BEFORE BUILD..\"\n.\/hammerdbcli auto buildcli.tcl\necho \"BASH SCRIPT AFTER BUILD..\"<\/pre>\n<p>When run the output looks as follows:<\/p>\n<pre>.\/build.sh\nBASH SCRIPT BEFORE BUILD..\nHammerDB CLI v3.2\nCopyright (C) 2003-2019 Steve Shaw\nType \"help\" for a list of commands\nThe xml is well-formed, applying configuration\nSETTING CONFIGURATION\nDatabase set to Oracle\n...\nVuser 2:FINISHED SUCCESS\nVuser 1:Workers: 0 Active 2 Done\nVuser 1:CREATING TPCC INDEXES\nVuser 1:CREATING TPCC STORED PROCEDURES\nVuser 1:GATHERING SCHEMA STATISTICS\nVuser 1:TPCC SCHEMA COMPLETE\nVuser 1:FINISHED SUCCESS\nALL VIRTUAL USERS COMPLETE\nBASH SCRIPT AFTER BUILD..<\/pre>\n<p>As per the original intention this can also be driven from a Windows batch script for automation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By default the HammerDB command line interface was designed to run interactively. However many people wanted to run it from a script and an example to do this was shown here. However this only worked on Linux and therefore @xychar proposed a modification to run command line scripts directly instead of typing commands by hand &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.hammerdb.com\/blog\/uncategorized\/running-hammerdbcli-from-a-bash-or-batch-script-updated-for-v3-2\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Running hammerdbcli from a bash or batch script updated for v3.2&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"ppma_author":[5],"class_list":["post-426","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"authors":[{"term_id":5,"user_id":2,"is_guest":0,"slug":"hammerdb","display_name":"HammerDB","avatar_url":{"url":"https:\/\/www.hammerdb.com\/blog\/wp-content\/uploads\/2018\/10\/logo-white.png","url2x":"https:\/\/www.hammerdb.com\/blog\/wp-content\/uploads\/2018\/10\/logo-white.png"},"author_category":"","user_url":"http:\/\/www.hammerdb.com","last_name":"","first_name":"","job_title":"","description":""}],"_links":{"self":[{"href":"https:\/\/www.hammerdb.com\/blog\/wp-json\/wp\/v2\/posts\/426","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hammerdb.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hammerdb.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hammerdb.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hammerdb.com\/blog\/wp-json\/wp\/v2\/comments?post=426"}],"version-history":[{"count":4,"href":"https:\/\/www.hammerdb.com\/blog\/wp-json\/wp\/v2\/posts\/426\/revisions"}],"predecessor-version":[{"id":430,"href":"https:\/\/www.hammerdb.com\/blog\/wp-json\/wp\/v2\/posts\/426\/revisions\/430"}],"wp:attachment":[{"href":"https:\/\/www.hammerdb.com\/blog\/wp-json\/wp\/v2\/media?parent=426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hammerdb.com\/blog\/wp-json\/wp\/v2\/categories?post=426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hammerdb.com\/blog\/wp-json\/wp\/v2\/tags?post=426"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.hammerdb.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}