-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathupdate_status_fields.sh
More file actions
114 lines (96 loc) · 3.51 KB
/
update_status_fields.sh
File metadata and controls
114 lines (96 loc) · 3.51 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
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
#!/bin/bash
# The above line should be the shell you wish to execute this script.
#
# VERSION="2.0.1"
# MODIFIED="Nov 14, 2024"
# remote.it Example Script for setting Status A-E
# Status A = Free disk space, listed by partition
# Status B = Linux version info from uname -a
# Status C = System uptime since last boot
# Status D = List of all running processes
# Status E = Shell version
#
#
# These environment Variables are available to the script:
# JOB_DEVICE_ID - The job device ID of the device being managed
# GRAPHQL_API_PATH - The GraphQL API path to the remote.it api server
exec > ./external_script.log 2>&1
set -x # Start logging all commands executed
# A Function to set a single status (statusA, statusB, statusC, etc.)
# Status columns can be displayed on the device list
# $1 = status letter (e.g., 'a')
# $2 = status value (e.g., 'some value')
Status()
{
SHORTHAND=$(echo "$1" | tr '[:lower:]' '[:upper:]')
ATTRIBUTE_NAME="\$remoteit.status${SHORTHAND}"
ATTRIBUTE_VALUE="$2"
# Send the data to the API, including jobDeviceId and attributeName in the URL
curl -X POST "https://${GRAPHQL_API_PATH}/job/attribute/$JOB_DEVICE_ID/$ATTRIBUTE_NAME" \
-H "Content-Type: text/plain" \
--data "$ATTRIBUTE_VALUE"
}
# Function to Log data to a file
Log()
{
echo "$1" >> $0.log
}
# Clear Status
Status a ""
Status b ""
Status c ""
Status d ""
Status e ""
#-------------------------------------------------
# Update status column A in remote.it portal with free disk space
# retrieve the free disk space
diskfree="$(df)"
Log "Status a diskfree: $diskfree"
# send to status column a in remote.it portal
Status a "$diskfree"
#-------------------------------------------------
#-------------------------------------------------
# Update status column B in remote.it portal with kernel
# retrieve the Linux kernel version
fwversion="$(uname -a)"
Log "Status b fwversion: $fwversion"
# send to status column b in remote.it portal
Status b "$fwversion"
#-------------------------------------------------
#-------------------------------------------------
# Update status column C in remote.it portal with uptime
# retrieve the system uptime
uptime="$(uptime)"
Log "Status c uptime: $uptime"
# send to status column c in remote.it portal
Status c "$uptime"
#-------------------------------------------------
#-------------------------------------------------
# Update status column D in remote.it portal with vmstat
# get the list of running processes
# Check if vm_stat is available (common on macOS)
if command -v vm_stat &> /dev/null; then
vmstat_output="$(vm_stat)"
# Otherwise, check if vmstat is available (common on Linux)
elif command -v vmstat &> /dev/null; then
vmstat_output="$(vmstat)"
else
# If neither command is available, set vmstat_output to an error message
vmstat_output="Neither vm_stat nor vmstat is available on this system."
fi
Log "Status d vmstat: $vmstat_output"
# set attribute for vmstat
Status d "$vmstat_output"
#-------------------------------------------------
#-------------------------------------------------
# Update status column E in remote.it portal with OS
# retrieve the os ID as reported by the command “cat /etc/os-release”
os=$(cat /etc/os-release | grep -w ID | awk -F "=" '{print $2 }')
# send to status column e in remote.it portal
Status e "$os"
#-------------------------------------------------
#=======================================================================
# Lastly finalize job, no updates allowed after this
exit 0
# Use this line in case of error
# exit 1