philchillbill wrote:
> Good to hear. If you run the script manually from the command line, it
> should respond with OK 1 if the updating went well (the '1' means one
> tunnel was updated).
>
> Regarding brackets:
>
> [] delimits an array or list. In this case the array only has one member
> because you have a single tunnel, but it is still an array.
> {} delimits an object, in this case a JSON object. JSON requires the use
> of "" around strings and will not tolerate ' unless it's inside a
> string.
> If you want to build a string out of a substring that contains "" then
> the outer quotes need to be ', or vice versa. So e.g. 'This is a "test"'
> or "This is a 'test'".
> The backtick ` means that what is inside is executed as code.
>
> In our case, the backticks are around the -wget -so it is executed and
> by wrapping the result of that execution in "" we can assign the result
> of that wget to URL and RES in a single command that runs/assigns.
Thanks for the explanations. Is it possible the backticks aren't
supported in pCP?
Anyway, the script that works for me to autostart and autoupdate ngrok,
either at boot as user 'root' or from the command line as user 'tc', is
as follows. Please let me know of any obvious blunders or suggestions.
Code:
--------------------
#!/bin/sh
# autostart and autoupdate ngrok for Media Server skill
# enter your own details here
AUTH="your username:your password"
SVR="192.168.x.x:9000"
UUID="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" #from account linking step
logfile="/home/tc/ngrok.log"
#path to ngrok executable. Big file, keep it out of the pCP backup, e.g. put
it on the third partition
ngrok_exec="/mnt/PCP_DATA/ngrok/ngrok"
# make sure ngrok is started by the authorised user, i.e. 'tc'. When run as
a user command at boot, the user is 'root'
user=$(id | awk -F\( {'print $2'} | awk -F\) {'print $1'})
if [ $user = "tc" ]; then # ngrok command can be run without modification
$ngrok_exec http -auth $AUTH $SVR > /dev/null 2>&1 &
elif [ $user = "root" ];then # force ngrok command to be run by user 'tc'
sudo -u tc $ngrok_exec http -auth $AUTH $SVR > /dev/null 2>&1 &
fi
sleep $1 # send sleep time in seconds as command line parameter:
# 1 second seems to be enough once booted, 5 seconds to
play safe during boot.
# get new URL
URL=https://$(curl -s http://localhost:4040/api/tunnels | awk -F\"https://
{'print $2'} | awk -F\" {'print $1'})
date > /home/tc/ngrok.log
echo "URL = "$URL >> $logfile
# construct JSON data
DATA=[{\"name\":\"false\",\"url\":\"${URL}\"}]
echo "DATA = "$DATA >> $logfile
#see what the update command looks like
CMD=$(echo wget -qO-
https://smartskills.tech/linking/updateNgrok.php?uuid=$UUID\&data=$DATA)
echo "CMD = "$CMD >> $logfile
#send the update command
RES=$(wget -qO-
https://smartskills.tech/linking/updateNgrok.php?uuid=$UUID\&data=$DATA)
echo "RES = "$RES >> $logfile
--------------------
------------------------------------------------------------------------
chill's Profile: http://forums.slimdevices.com/member.php?userid=10839
View this thread: http://forums.slimdevices.com/showthread.php?t=111016
_______________________________________________
plugins mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/plugins