File size: 9,199 Bytes
1d97050
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
CPSL (Custom Process Scripting Language) Documentation

1. Introduction
CPSL is a domain-specific scripting language designed for automating server management, database operations, and system administration tasks. It enables efficient interaction with servers, execution of shell commands, and control over processes and services.

2. Commands Overview
- R_ConnectServer: Connects to a remote server using its hostname or IP address.
  Example:
  R_ConnectServer "<Server_Name>"

- ExecuteShellCommandEnter: Executes a shell command on the connected server with an optional timeout.
  Example:
  ExecuteShellCommandEnter "hostname", "$", 5000

- R_DisconnectSSH: Disconnects the session from the connected server.
  Example:
  R_DisconnectSSH

- GetServerPass: Retrieves the password for a server.
  Example:
  GetServerPass("<Environment>", "<Server>", "<Key>")

- GetServerUser: Retrieves the username for a server.
  Example:
  GetServerUser("<Environment>", "<Server>", "<Key>")

3. Common Scripting Tasks

3.1 Update Hostname
Updates the hostname on a server and verifies the change.

R_ConnectServer "<Server_Name>"
ExecuteShellCommandEnter "sudo su - root", "$", 5000
ExecuteShellCommandEnter "hostnamectl set-hostname <New_Hostname>", "$", 5000
$v1 = ExecuteShellCommandEnter "hostname", "$", 5000
if (v1.contains("<New_Hostname>")) then
    R_DisconnectSSH
    return true
else
    R_DisconnectSSH
    return false
end

3.2 Container Platform Operations
Example for OCP login and operations:

R_ConnectServer "<Server_Name>"
ExecuteShellCommandEnter "oc login <Protocol>://<FQDN>:<Port> -u <Username> -p <Password>", "$", <Login_Timeout>
ExecuteShellCommandEnter "oc project <Project_Name>", "$", <Project_Timeout>
ExecuteShellCommandEnter "<Scale_Command>", "$", <Operation_Timeout>
$v1 = ExecuteShellCommandEnter "<Status_Command>", "$", <Status_Timeout>
if (v1.contains("<Status_Pattern>")) then
    R_DisconnectSSH
    return true
else
    R_DisconnectSSH
    return false
end

3.3 Service Instance Management
Example for service control:

R_ConnectServer "<Server_Name>"
ExecuteShellCommandEnter "sudo su - <Service_User>", "$", <Auth_Timeout>
ExecuteShellCommandEnter "cd <Service_Path>", "$", <Path_Timeout>
$v1 = ExecuteShellCommandEnter "sh <Service_Script>", "$", <Execute_Timeout>
if (v1.contains("<Status_Pattern>")) then
    R_DisconnectSSH
    return true
else
    R_DisconnectSSH
    return false
end

3.4 Log Monitoring with Loop
Example for continuous log monitoring:

R_ConnectServer "<Server_Name>"
ExecuteShellCommandEnter "cd <Log_Path>", "$", <Path_Timeout>
loop
$v1 = ExecuteShellCommandEnter "tail -100 <Log_File>", "$", <Monitor_Timeout>
if (v1.contains("<Success_Pattern>")) then
    R_DisconnectSSH
    clearfile
else
    Wait <Interval>
    Breakloopaftercycle(<Max_Cycles>)
    goto loop
end

3.5 File Operations
Example for file management:

R_ConnectServer "<Server_Name>"
ExecuteShellCommandEnter "cd <Path>", "$", <Path_Timeout>
$v1 = ExecuteShellCommandEnter "<File_Operation>", "$", <Operation_Timeout>
if (v1.contains("<Success_Pattern>")) then
    R_DisconnectSSH
    return true
else
    R_DisconnectSSH
    return false
end

3.6 Start EnterpriseLink Cluster Server
Starts the EnterpriseLink Cluster Server service and verifies it.

R_ConnectServer "<Server_Name>"
ExecuteShellCommandEnter "sudo su - root", "$", 5000
$v1 = ExecuteShellCommandEnter "/etc/init.d/EnterpriseLinkClusterServer start", "$", 5000
if (v1.contains("Starting EnterpriseLink Cluster Server")) then
    R_DisconnectSSH
    return true
else
    R_DisconnectSSH
    return false
end

3.7 Copy Files to Another Server
Copies a file from one server to another using SCP.

R_ConnectServer "<Source_Server_Name>"
ExecuteShellCommandEnter "scp <File_Path> <Destination_User>@<Destination_IP>:<Destination_Path>", "$", 5000
ExecuteShellCommandEnter "yes", "$", 5000
$v1 = ExecuteShellCommandEnter "ls <Destination_Path>", "$", 5000
if (v1.contains("<File_Name>")) then
    R_DisconnectSSH
    return true
else
    R_DisconnectSSH
    return false
end

3.8 MySQL Operations
Starts MySQL replication and verifies the process.

R_ConnectServer "<Server_Name>"
ExecuteShellCommandEnter "mysql -u <Username> -p", "$", 5000
ExecuteShellCommandEnter "start slave;", "$", 5000
$v1 = ExecuteShellCommandEnter "show slave status\G", "$", 5000
if (v1.contains("Running")) then
    R_DisconnectSSH
    return true
else
    R_DisconnectSSH
    return false
end

3.9 Manage SnapMirror

Quiesce SnapMirror Replication:
R_ConnectServer "<Storage_Server_Name>"
$v1 = ExecuteShellCommandEnter "snapmirror quiesce -destination-path <Path>", "$", 5000
if (v1.contains("Operation succeeded")) then
    R_DisconnectSSH
    return true
else
    R_DisconnectSSH
    return false
end

Break SnapMirror Replication:
R_ConnectServer "<Storage_Server_Name>"
$v1 = ExecuteShellCommandEnter "snapmirror break -destination-path <Path>", "$", 5000
if (v1.contains("Operation succeeded")) then
    R_DisconnectSSH
    return true
else
    R_DisconnectSSH
    return false
end

4. Multiple Server Operation Patterns

4.1 Single Server, Multiple Operations

R_Connect Server "<Server_Name>"
ExecuteShellCommandEnter "sudo su - <User>","",<Timeout>
$v1 = ExecuteShellCommandEnter "<Command_1>","",<Timeout_1>
if($v1.notcontains("<Success_Pattern_1>")) then
    R_DisconnectSSH
    return false
else
    $v2 = ExecuteShellCommandEnter "<Command_2>","",<Timeout_2>
    if($v2.notcontains("<Success_Pattern_2>")) then
        R_DisconnectSSH
        return false
    else
        R_DisconnectSSH
        return true
    end
end

4.2 Multiple Servers, Sequential Operations

R_Connect Server "<Server_1>"
ExecuteShellCommandEnter "sudo su - <User_1>","",<Timeout>
$v1 = ExecuteShellCommandEnter "<Command_1>","",<Timeout_1>
if($v1.notcontains("<Success_Pattern_1>")) then
    R_DisconnectSSH
    return false
else
    R_Connect Server "<Server_2>"
    ExecuteShellCommandEnter "sudo su - <User_2>","",<Timeout>
    $v2 = ExecuteShellCommandEnter "<Command_2>","",<Timeout_2>
    if($v2.notcontains("<Success_Pattern_2>")) then
        R_DisconnectSSH
        return false
    else
        R_DisconnectSSH
        return true
    end
end

4.3 Multiple Servers, Parallel Operations

R_Connect Server "<Server_1>"
ExecuteShellCommandEnter "sudo su - <User_1>","",<Timeout>
$v1 = ExecuteShellCommandEnter "<Command_1>","",<Timeout_1>
R_DisconnectSSH

R_Connect Server "<Server_2>"
ExecuteShellCommandEnter "sudo su - <User_2>","",<Timeout>
$v2 = ExecuteShellCommandEnter "<Command_2>","",<Timeout_2>
R_DisconnectSSH

R_Connect Server "<Server_3>"
ExecuteShellCommandEnter "sudo su - <User_3>","",<Timeout>
$v3 = ExecuteShellCommandEnter "<Command_3>","",<Timeout_3>
R_DisconnectSSH

if($v1.notcontains("<Success_Pattern_1>") or $v2.notcontains("<Success_Pattern_2>") or $v3.notcontains("<Success_Pattern_3>")) then
    return false
else
    return true
end

4.4 Best Practices for Multiple Server Operations:
- Use appropriate timeout values for each operation
- Implement proper error handling and validation for each server connection and command execution
- Disconnect from servers after completing operations or in case of errors
- Use consistent naming conventions for variables and placeholders
- Structure the script logically, grouping related operations together
- Consider using loops for repetitive operations across multiple servers
- Implement appropriate logging or output messages for troubleshooting
- Use .contains() or .notcontains() based on the expected output patterns
- Ensure proper indentation and nesting of if-else statements for readability

Common Timeout Values:
- Authentication: 5000-60000
- Basic operations: 5000
- Service operations: 120000-300000
- Platform operations: 60000-120000
- Recovery operations: 300000-1200000

Best Practices:
- Use empty string for second parameter
- Include R_DisconnectSSH in all paths
- Validate each operation before proceeding
- Match number of 'end' statements with if blocks
- Follow proper nesting structure
- Use appropriate timeout values
- Use .contains() or .notcontains() based on validation needs


4.5 Best Practices for Multiple Server Operations:
- Use empty string "" for second parameter in ExecuteShellCommandEnter
- Implement proper timeout values for each operation
- Follow nested if-else structure for validations
- Include R_DisconnectSSH in each failure path
- Match 'end' statements with if blocks
- Use .contains() or .notcontains() based on validation needs
- Maintain consistent prompt patterns
- Follow proper command sequence
- Implement appropriate validation checks

5. Best Practices
- Always sanitize inputs to avoid hardcoding sensitive information
- Use placeholders in templates and replace them with real values during execution
- Test scripts in a controlled environment before deploying them in production
- Set appropriate timeout values based on operation type
- Implement proper validation checks for operations
- Include error handling for all operations

6. Common Timeout Values
- Basic operations: 5000
- Authentication operations: 60000
- Path operations: 60000
- Service operations: 300000
- Build operations: 900000