How to write COS code inside a unix script
Here you have an easy way to write and execute COS code from your unix scripts. This way one does not need to write routines or even open Studio or Atelier. It can be an option for simple and small actions for instance things like installation tasks or compiling.
See sample bash script (compile.sh) to compile classes:
#!/bin/bash ##################################################################### # Script to compile classes # $1 = NAMESPACE # $2 = ClassName # # For example: # ./compile.sh "SAMPLES" "Sample.Person" ##################################################################### echo -n "username:" read username echo -n "password:" read pwd csession HSINSTANCE -U "$1" <<EOFF $username $pwd set status = \$SYSTEM.OBJ.Compile("$2") h EOFF
This is the output from the console:
~/>./compile.sh "SAMPLES" "Sample.Person" username:Admin password:*** Node: mycomputer.com, Instance: HSINSTANCE Username: Password: SAMPLES> Compilation started on 10/13/2016 16:27:29 with qualifiers '' Compiling class Sample.Person Compiling table Sample.Person Compiling routine Sample.Person.1 Compilation finished successfully in 0.295s. SAMPLES> ~/>
Hope someone finds it useful !
Worth mentioning that O/S authentication is simpler and potentially more secure than fiddling with passwords in a script. If you do prompt for a password, consider using the -s option of the read command to hide the input.
This could also be very useful when you would like to configure your Ensemble production to start automatically on UNIX OS boot. It can be done in two steps: 1. Put "ccontrol start <INSTANCE NAME>" in a script that would run at OS start up; 2. Configure the production to start automatically upon Ensemble instance start up through the Management Portal -> Ensemble -> Manage -> Auto-Start Production.