Creating and Running gfsh Command Scripts

gfsh offers several ways to run commands in a scripting environment.

Running gfsh Scripts

You can create and run scripts that contain gfsh commands that you wish to execute. To execute the script, use the gfsh run command. For example:
gfsh run --file=mycommands.gfsh
Note: When you run a gfsh script, interactive parameters are ignored. You can also set the script to run in quiet mode to prevent output and instruct the script to skip any errors it encounters.

Your command history file can be helpful when you write a gfsh script. A history of commands that have been executed successfully is logged in the .gfsh.history file in the home directory of the user running gfsh. You can also export a history file with the history --file=your_file_name command.

Running gfsh Commands on the OS Command Line

You can run some gfsh commands directly from your operating system's prompt by preceding the command with gfsh. This can be useful for Unix shell or Windows batch scripting. For example:
C:\PivotalGemFire70\Latest\>gfsh start locator --name=locator2 --port=10335
If the command is successful, the output appears and the operating system prompt reappears:
Locator in C:\PivotalGemFire70\Latest\locator2 on GemFireStymon[10335] as 
locator2 is currently online.
Process ID: 4000
Uptime: 12 seconds
GemFire Version: 7.0
Java Version: 1.6.0_26
Log File: C:\PivotalGemFire70\Latest\locator2\locator2.log
JVM Arguments: -Dgemfire.launcher.registerSignalHandlers=true 
Class-Path: ;C:\PivotalGemFire70\Latest\lib\gfsh-dependencies.jar;
C:\Program Files\Java\jdk1.6.0_26\lib\tools.jar
To see which gfsh commands are available directly on the prompt:
prompt# gfsh help
The following output appears:
Pivotal GemFire(TM) v7.0.1 Command Line Shell

gfsh [ <command [options]> | <help [command] | [-e "<command> [options]"]* ]

compact offline-disk-store
    Compact an offline disk store. If the disk store is large, additional memory
 may need to be allocated to the process using the --J=-Xmx??? parameter.
describe offline-disk-store
    Display information about an offline disk store.
encrypt password
    Encrypt a password for use in data source configuration.
    Execute a set of GFSH commands. Commands that normally prompt for additional
 input will instead use default values.
start jconsole
    Start the JDK's JConsole tool in a separate process. JConsole will be launch
ed, but connecting
    to GemFire must be done manually.
start jvisualvm
    Start the JDK's Java VisualVM (jvisualvm) tool in a separate process. Java 
VisualVM will be launched, but connecting to GemFire must be done manually.
start locator
    Start a Locator.
start pulse
    Open a new window in the default Web browser with the URL for the Pulse appl
start server
    Start a GemFire Cache Server.
start vsd
    Start VSD in a separate process.
status locator
    Display the status of a Locator. Possible statuses are: started, online, off
line or not
status server
    Display the status of a GemFire Cache Server.
stop locator
    Stop a Locator.
stop server
    Stop a GemFire Cache Server.
validate offline-disk-store
    Scan the contents of a disk store to verify that it has no errors.
    Display product version information.

    Start GFSH in interactive mode.
gfsh help start locator
    Display help for the "start locator" command.
gfsh start locator --name=locator1
    Start a Locator with the name "locator1".
gfsh -e "connect" -e "list members"
    Connect to a running Locator using the default connection information and 
run the "list
    members" command.
To summarize, you can run the following gfsh commands directly from the operating system shell:
  • gfsh compact offline-disk-store
  • gfsh describe offline-disk-store
  • gfsh encrypt password
  • gfsh run
  • gfsh start jconsole
  • gfsh start jvisualvm
  • gfsh start locator
  • gfsh start pulse
  • gfsh start server
  • gfsh start vsd
  • gfsh status locator
  • gfsh status server
  • gfsh stop locator
  • gfsh stop server
  • gfsh validate offline-disk-store
  • gfsh version
To run multiple commands directly on the command line:
prompt>gfsh -e "start locator --name=locator1" -e "start server --name=server1"

prompt>gfsh -e "start jconsole"

prompt>gfsh -e "connect --locators=remotehost[10334]" -e "rebalance" -e "gc"