I have a folder that I want to pause and resume on a schedule; I found HOWTO: Resume via CLI which I allows me to resume all paused folders.
However I don’t know how to pause a specific folder on a schedule. Can anyone let me know how to do tackle this one.
Pause on folder a boolean flag on the config object of the folder, so you have to get the config, flip the flag on the folders you want and post it back.
Ok so I am almost there; i am just not getting the updated data being sent to the config.
If I remove the “= false” from jq the script returns the current value of the folder I’m interested in.
#!/bin/bash
set -euo pipefail
folder=$1
echo "resuming "$folder
st='http://localhost:8384/rest/system/config'
key='myKey'
f=$(mktemp)
function clean {
rm -f "$f"
}
trap clean EXIT
curl -s -H X-API-Key:$key $st > $f
jq -r '.folders[] | select(.label=='\"$folder\"') | .paused = false' "$f"
curl -s -H X-API-Key:$key --data-binary @"$f" $st
So there is a stcli binary that makes this a lot easier, I think its not shipped part of the official release.
https://build.syncthing.net/viewLog.html?buildId=61305&buildTypeId=Syncthing_Tools&tab=artifacts#
I think just outputs the modified content to stdout, so you might need to redirect to $f
Ok now it is getting a bit weird. I am getting a “Decoding posted config: unexpected end of JSON input” error.
When I don’t execute the jq there is no error.
This is the code that I am using now. Not too different then the above.
set -euo pipefail
folder=$1
echo "resuming "$folder
st='http://localhost:8384/rest/system/config'
key='myKey'
f=$(mktemp)
function clean {
rm -f "$f"
}
trap clean EXIT
curl -s -H X-API-Key:$key $st > "$f"
cat $f > orig.txt
#jq -r '(.folders[] | select(.label=='\"$folder\"')) .paused = false' "$f" > "$f"
jq -r '(.folders[] | select(.label=='\"$folder\"')) .paused = false' "$f" > output.txt
curl -s -H X-API-Key:$key --data-binary @"$f" $st
I run a diff on orig.txt and output.txt and the only change is the one I want;
diff result
< "paused": true,
---
> "paused": false,
You might need content type headers, and I am not sure if @"$f" does the right thing. As I said, using the cli would probably make this much easier.
Got it; turns out that reusing the temp file “f” doesn’t work; having a second temp file “o” works.
#!/bin/bash
set -euo pipefail
folder=$1
echo "resuming "$folder
st='http://localhost:8384/rest/system/config'
key='myKey'
f=$(mktemp)
o=$(mktemp)
function clean {
rm -f "$f"
rm -f "$o"
}
trap clean EXIT
curl -s -H X-API-Key:$key $st > "$f"
#cat $f > orig.txt
jq --arg fldr "$folder" -r '(.folders[] | select(.label==$fldr)) .paused = false' "$f" > $o
#jq --arg fldr "$folder" -r '(.folders[] | select(.label==$fldr)) .paused = false' "$f" > output.txt
curl -s -H X-API-Key:$key --data-binary @$o $st
Now I have a nice little function that I can call with a folder name and it will resume; I will make a copy of this called pause and change the false to true.
i.e.
~/myScripts/Resume.sh aFolder
~/myScripts/Pause.sh aFolder
1 Like
@AudriusButkevicius thanks for all your help.
1 Like
All working now!
See: stackoverflow for the help I got with specific jq questions.
system
(system)
Closed
May 18, 2020, 11:40am
11
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.