Home > Enterprise >  Sending multiline command output via wget as post-data
Sending multiline command output via wget as post-data

Time:05-27

I'm trying to run a command that will send a POST request with data that is a result of another command. An example will say it all:

wget -O- --post-data=$(ls -lah) http://192.168.30.53/api/v2/network/clients

This is obviously wrong, but I have no idea how to "escape" the value of ls -lah command before passing it as a parameter.

Current output if needed:

wget: invalid option -- '>'
wget: --wait: Invalid time period '-r--r--'

CodePudding user response:

You do not escape - you quote the usage. Check your scripts with shellcheck.

... --post-data="$(ls -lah)" ...

CodePudding user response:

I have no idea how to "escape" the value of ls -lah command before passing it as a parameter.

wget man page describe --post-data=string and --post-file=file in unison, relevant for this case is that

--post-data sends string as data, whereas --post-file sends the contents of file. Other than that, they work in exactly the same way.

and that

argument to "--post-file" must be a regular file

due to above limitation piping stdin would not work, but that is not problem unless you are banning from creating normal files - just create temporary file for that, something like that

ls -lah > lsdata
wget -O- --post-file=lsdata http://192.168.30.53/api/v2/network/clients
rm lsdata

should work (I do not have ability to test it)

  • Related