Old ways to submit an LDAS user command
(these no longer work, now that password encryption is mandatory)

Peter Shawhan

Using plain Tcl

Originally, before the password encryption protocol was made mandatory, it was possible to write a simple Tcl script to take care of all the communication with LDAS without using the ldasjob library. The following is a complete example that worked as is (after substituting your LDAS username/password and your email address). (The tclshexe shell is a special LIGOtools version of tclsh, so you can run this script whether or not Tcl/Tk is installed elsewhere on your computer. However, the regular tclsh, version 7.5 or later, will run this script just as well.)
#!/usr/bin/env tclshexe

# Set the host and port of the LDAS manangerAPI
set hostName "ldas.ligo-wa.caltech.edu"
set port 10001

# Set the user command
set ldasCmd "ldasJob\
{-name myname -password blah -email me@ligo.caltech.edu}\
{getMetaData -returnprotocol http:out.xml -outputformat LIGO_LW\
-sqlquery {select tabname from syscat.tables} }"

# Open a socket to the LDAS managerAPI
if { [catch {socket $hostName $port} sockId] } {
    puts "Unable to connect to LDAS manager"
    exit
}

# Send the LDAS command
puts $sockId $ldasCmd
flush $sockId

# Get the response from the managerAPI and print it out
set jobInfo [read $sockId]
puts $jobInfo

# Close the socket connection and exit
close $sockId
exit

Using perl

The perl version has basically the same structure as the Tcl version:
#!/usr/bin/env perl

# Set the host and port of the LDAS manangerAPI
$hostName = "ldas.ligo-wa.caltech.edu";
$port = 10001;

# Set the user command (note that the "@" is escaped)
$ldasCmd = "ldasJob"
. " {-name myname -password blah -email me\@ligo.caltech.edu}"
. " {getMetaData -returnprotocol http:out.xml -outputformat LIGO_LW"
. " -sqlquery {select tabname from syscat.tables} }";

# Open a socket to the LDAS managerAPI
use IO::Socket;
$sockId = IO::Socket::INET->new( Proto    => "tcp",
                                 PeerAddr => $hostName,
                                 PeerPort => $port )
    or die "Unable to connect to LDAS manager, aborting";

# Send the LDAS command
print $sockId $ldasCmd;

# Get the response from the managerAPI and print it out
@jobInfo  = <$sockId>;
print @jobInfo;

# Close the socket connection and exit
close $sockId;
exit;

From a C program

Setting up a socket in a C program requires a fair amount of code, but the libdataflow.a library in the LIGOtools dataflow package includes some utility routines to make it easy:
#include "DfSocket.h"

/*===========================================================================*/
int main(void)
{
  char host[] = "ldas.ligo-wa.caltech.edu";
  int port = 10001;
  char command[] = "ldasJob {-name myname -password blah -email me@ligo.caltech.edu} {getMetaData -returnprotocol http:out.xml -outputformat LIGO_LW -sqlquery {select tabname from syscat.tables} }";
  char buf[65536];
  int status;

  status = DfSocketCommand( host, port, command, buf, sizeof(buf) );

  printf( "Status is %d\n", status );
  printf( "Output is:\n%s\n", buf );

  return status;
}
To compile this on Solaris, do:

 gcc mycmd.c $LIGOTOOLS/lib/libdataflow.a -I$LIGOTOOLS/include -L/usr/lib -lsocket -lnsl -o mycmd

To compile it on Linux, do:

 gcc mycmd.c $LIGOTOOLS/lib/libdataflow.a -I$LIGOTOOLS/include -o mycmd