Create easy templates for creating jobs etc using linux

44 views
Skip to first unread message

wim.ve...@billinghouse.nl

unread,
Sep 25, 2018, 4:27:09 PM9/25/18
to schedulix
I recently had to create a script to create the same jobs for multiple environments.

I came up with the following solution:

I create a template file with the commands. The part that is variable per environment I replace with placeholders like #ENV# so you get a statement like

-- snippet start template.sdm  --
#
# create the top level folder
#
create or alter folder SYSTEM.'#ENV#' 
with
group='PUBLIC',
environment=none,
inherit grants = none,
parameters = (
TARGET_NODE = '#NODE#'
);
-- snippet end template.sdm --

I then also created a simple shell script that will remove the # comments (I hate the /* */ comments :)) and replaces the placeholders. This looks like this :

-- snippet start --
#!/bin/bash

usage() {
echo "$0 <name of target system> <url>"
echo "  example: $0 TEST https://dev11.nova.essent.be/billing-esbe"
exit 1
}

if [ $# -ne 2 ]
then
usage
fi

# first two sed invocations will remove the remarks in template sdm file. The others will replace the actual placeholders.
# Note that the we also use % as substitute separator, this is because the URL can contain /, which messes up the command.
# Finally the result will be fed into sdmsh to make the database entries.
#
cat template.sdm | sed 's/# .*$//' | sed 's/^#$//' | sed s%#ENV#%$1%g | sed s%#NODE#%$2%g | sdmsh
-- snippet end--

It works very nice for me, maybe it helps somebody else.

Regards,
Wim Veldhuis.
Reply all
Reply to author
Forward
0 new messages