STEAM GROUP
Archi's SC Farm Archi-ASF
STEAM GROUP
Archi's SC Farm Archi-ASF
53,407
IN-GAME
365,962
ONLINE
Founded
October 29, 2015
Language
English
Atari Nov 4, 2018 @ 9:55am
How to use asf through a terminal?
I've ASF on a raspi and can connect to it through ssh. Normaly I use IPC and sent commands with curl: curl -H "Authentication: password" -X POST -d '' http://127.0.0.1:1242/Api/Command/status%20asf but I guess this isn't the best way to use it. Especially with latest versions there isn't a new line after the response from asf anymore. I haven't found a proper solution for me in the wiki nor the discussions. I would appreciate it if anyone could help me to either improve my curl command or tell me how I could use asf on a proper way. Thanks.
Last edited by Atari; Nov 4, 2018 @ 11:57pm
Originally posted by Rudokhvist:
Most basic (and thus not very usable) script will look as something like this:
#!/bin/bash curl -H "Authentication: $1" -X $2 -d '' http://127.0.0.1:1242/Api/$3 echo
Let's say you saved it with filename "ipc", made it executable with "chmod +x ipc", now you can call it like
./ipc password POST Command/status%20asf
.Of course, if you don't worry about security you can just put password to bash file too (after all, it's already stored in plain text in asf config, and if you only use commands, and never other IPC api, you can put POST method and "command" endpoint in there too... making it look like this
#!/bin/bash curl -H "Authentication: password" -X POST -d '' http://127.0.0.1:1242/Api/Command/$1 echo
And invoke it as
./ipc status%20asf
Or, you can even add separators to it, like this
#!/bin/bash cmd="" for i in "$@" do cmd=$cmd$i"%20" done curl -H "Authentication: password" -X POST -d '' http://127.0.0.1:1242/Api/Command/$cmd echo
And invoke it as simple as
./ipc status asf
< >
Showing 1-6 of 6 comments
Archi Nov 4, 2018 @ 7:08pm 
Why should there be a newline? This is implementation detail so comparing it to past version achieves nothing, it's the JSON answer that should be parsed, interpreted and displayed (if one wants to), not the raw response - and for that you don't need a newline because JSON ends with }.

If you for some unknown to me reason require a newline on the end then you can add appropriate logic whether there is one or not and add it yourself if needed. ASF doesn't need to append newline at the end of the response if it's not required by RFC of HTTP protocol.
Last edited by Archi; Nov 4, 2018 @ 7:15pm
Atari Nov 4, 2018 @ 11:46pm 
I didn't want to say with my post that anything is wrong or should be changed in asf. Maybe my usage of ipc isn't the best way but I don't know how to use it on a better/proper way. The curl method is the only way I know to use it with only a terminal and I don't know how to improve the curl command to get a new line. I hoped that someone had an easy solution like add "xyz to your command and you have a new line" for me.
Rudokhvist Nov 5, 2018 @ 5:04am 
make a bash script (or .cmd file, if you are under windows), that will call curl with your parameters and output extra newline after curl output.
Atari Nov 5, 2018 @ 8:16am 
Thanks Ryzhehvost. Your solution makes sense for me. Now I only have to figure out how to achieve this as I have never written a bash script myself (the raspberry runs with raspbian). But I guess I can get help for this in some linux forums.
Last edited by Atari; Nov 5, 2018 @ 8:22am
The author of this thread has indicated that this post answers the original topic.
Rudokhvist Nov 5, 2018 @ 10:54am 
Most basic (and thus not very usable) script will look as something like this:
#!/bin/bash curl -H "Authentication: $1" -X $2 -d '' http://127.0.0.1:1242/Api/$3 echo
Let's say you saved it with filename "ipc", made it executable with "chmod +x ipc", now you can call it like
./ipc password POST Command/status%20asf
.Of course, if you don't worry about security you can just put password to bash file too (after all, it's already stored in plain text in asf config, and if you only use commands, and never other IPC api, you can put POST method and "command" endpoint in there too... making it look like this
#!/bin/bash curl -H "Authentication: password" -X POST -d '' http://127.0.0.1:1242/Api/Command/$1 echo
And invoke it as
./ipc status%20asf
Or, you can even add separators to it, like this
#!/bin/bash cmd="" for i in "$@" do cmd=$cmd$i"%20" done curl -H "Authentication: password" -X POST -d '' http://127.0.0.1:1242/Api/Command/$cmd echo
And invoke it as simple as
./ipc status asf
Atari Nov 5, 2018 @ 11:25am 
My solution for now was:
#!/bin/sh curl -H "Authentication: password" -X POST -d '' "http://127.0.0.1:1242/Api/Command/${*}" printf "\n"
I guess with your suggestion I can improve this further. Thanks.
Last edited by Atari; Nov 5, 2018 @ 11:54am
< >
Showing 1-6 of 6 comments
Per page: 1530 50

Date Posted: Nov 4, 2018 @ 9:55am
Posts: 6