-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript-test.sh
More file actions
executable file
·55 lines (49 loc) · 1.76 KB
/
script-test.sh
File metadata and controls
executable file
·55 lines (49 loc) · 1.76 KB
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
#!/bin/bash
# Script to be copied over to the host, and executed.
# The script should exit with a line echoing out the
# error or success message, and should then be followed
# by an error code 0 if ok, and >0 if not ok.
##
# The HOSTNAME environmental variable is passed on to
# the host when the ssh session are initiated within
# the wrapper script. It is read from the hosts.txt
# file which should be in the format:
# 10.10.10.1,myhostnamehere
## The ${NODENAME} env variable is taken from the nodename part in the hosts.txt file,
## and is exported directly in the ssh command when executed, and can be used within
## the script in the following way.
##
# cat >/etc/hostname <<EOF
# ${NODENAME}
# EOF
## Only the last error is read by the from ssh in the main program, so we can add more
## things to do like for example this
##
# progName="myservice"
# if ! systemctl stop $progName.service >/dev/null 2>&1; then
# echo "*" error: systemctl stop $progName.service
# exit 1
# fi
errorMessage=$(
# Redirect stderr to stdout for all command with the closure.
{
swupd info
# More commands can be added below within the parentheses.
} 2>&1
)
# ------- We're done, send output back to ssh client
# Check if all went ok with the previous command sequence, or if any errors happened.
# We return any result back to the ssh sessions which called this script by echoing
# the result, and do an exit <error code>.
# We can return one line back, so if more values are needed to be returned, they have
# to be formated into the same line.
#
# All went ok.
if [ $? -eq 0 ]; then
echo "successfully executed systemctl start wgkeepalive.service : $errorMessage"
exit 0
# An error happened.
else
echo "failed executing script: $errorMessage"
exit 1
fi