Skip to content

Commit d4e0f36

Browse files
committed
add another simple example
1 parent 9f7c093 commit d4e0f36

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

examples/write-to-file.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# https://github.com/mikhailnov/bashlib, https://abf.io/import/bashlib
4+
. bashlib ||{ echo "Failed to source bashlib!" ; exit 1 ;}
5+
6+
readonly file="/var/www/r8168.list"
7+
readonly lock="/var/www/r8168.lock"
8+
readonly rev="$(safe_param rev)"
9+
readonly probe="$(safe_param probe)"
10+
11+
# possible values: 0x15, 0x09
12+
if ! [[ "$rev" =~ ^0x..$ ]]; then
13+
echo "Incorrect value of rev"
14+
exit 1
15+
fi
16+
17+
if [ ${#probe} -gt 20 ] || ! [[ "$probe" =~ ^[a-zA-Z0-9]+$ ]]; then
18+
echo "Incorrect value of probe"
19+
exit 1
20+
fi
21+
22+
set -e
23+
echo "$rev;$probe" | flock "$lock" tee -a "$file" >/dev/null
24+
echo "Status: 200 OK"
25+
echo "Content-Type: text/plain; charset=utf-8"
26+
echo ""
27+
echo "OK"

0 commit comments

Comments
 (0)