Bash - POST : send image in message content - bash

I would like to send POST message using bash script.In body there should be image but i don't know how to put them.

You can use cURL for that:
curl -F File=#/path/to/your/file http://your.url
If that does not work, please add more details to your question.

Related

Rundeck Webhook to pass an argument to a shell script

I have a shell script which I would like to pass two arguments. The script accepts a hostname($1) and a directory name($2) as arguments
just_pull.sh HOSTNAME CONFIG_DIR
I have created a simple Rundeck job to run this script when the Webhook is called. I have gone through the documentation and it does not provide a way to do this as I am new to rundeck and its web API's. Passing the JSON value to the URL also throws a null value. I believe I am sending or receiving the data in an improper manner.
How can I define the arguments section in job and how to correctly add the {option.hostname} in Webhook arguments section.
Thanks #MegaDrive68k for the answer.
To elaborate the answer to my question,
I had to modify the job also. The 'Argument' section has to be filled with, ${option.hostname} ${option.conf}
Additionally the webhook should have -hostname ${data.field1} -conf ${data.field2} as 'Options'.
To call the Webhook, run the following command,
curl -H "Content-Type: application/json" -X POST -d '{"field1" : "localhost", "field2" : "conf"}' http://rundeckurl.com/api/38/webhook/aZmoByl0Hmasked8RkxBT8Oda#webhookname
The above command will pass the arguments to my script in question as,
just_pull.sh localhost conf
In this way. Basically you need to define the argument on the "Options" field (Webhook definition).

wkhtmltopdf with '?' in URL

My question is about use of '?' with wkhtmltopdf
Using StackOverflow advice, I have wkhtmltopdf working as invoked from a
php webpage...for example this works as expected:
$exec_string = "xvfb-run -a -s "."\"-screen 0, 1024x768x24 \""."
wkhtmltopdf http://example.com temp.pdf";
exec($exec_string);
However, if I add to the URL like this:
http://example.com/?page=clients
wkhtmltopdf ignores the page=clients and produces a pdf identical to the above result. I even tried surrounding with " as
...\"http://example.com/?page=clients \"...
but still no good.
How can I force wkhtmltopdf to pickup the the ?page=clients piece?
I've discovered my problem is more complicated than simply wkhtmltopdf not recognizing ?page=clients.
The website that the page belongs to does 'security' checks prior to displaying a page like this. An experiment done outside this framework shows me that wkhtmltopdf does indeed pickup the page=clients specification.

URL 404 Checker for bash

I want to write some code i can run in the bash that takes a list of URL's and checks if they return a 404. If the site is not returning a 404 i need the url to be written to the output list.
So in the end i should have a list with working sites.
I do not know how to realize the code.
This looks like something that could work right?:
How to check if a URL exists or returns 404 with Java?
You can use this code and build on it as necessary:
#!/bin/bash
array=( "http://www.stackoverflow.com" "http://www.google.com" )
for url in "${array[#]}"
do
if ! curl -s --head --request GET ${url} | grep "404 Not Found" > /dev/null
then
echo "Output URL not returning 404 ${url}"
fi
done
Thanks for your help. I found a package for linux called linkchecker. It does exactly what i want.

How to extract the source of a webpage without tags using bash?

We can download the source of the page using wget or curl , but I want to extract the source of the page without tags.
I mean extract it as text.
You can pipe to a simple sed command :
curl www.gnu.org | sed 's/<\/*[^>]*>//g'
Using Curl, Wget and Apache Tika Server (locally) you can parse HTML into simple text directly from the command line.
First, you have to download the tika-server jar from the Apache site:
https://tika.apache.org/download.html
Then, run it as a local server:
$ java -jar tika-server-1.12.jar
After that, you can start parsing text using the following url:
http://localhost:9998/tika
Now, to parse the HTML of webpage into simple text:
$ wget -O test.html YOUR-HTML-URL && curl -H "Accept: text/plain" -T test.html http://localhost:9998/tika
That should return the webpage text without tags.
This way you're using wget to download and save your desired webpage to "test.html" and then you use curl to send a request to the tika server in order to extract the text. Notice that it's necessary to send the header "Accept: text/plain" because tika can return several formats, not just plain text.
Create a Ruby script that uses Nokogiri to parse the HTML:
require 'nokogiri'
require 'open-uri'
html = Nokogiri::HTML(open 'https://stackoverflow.com/questions/6129357')
text = html.at('body').inner_text
puts text
Source
It would probably be simple to do with Javascript or Python if you're more comfortable with that, or search for a html-to-text utility. I imagine it would be very difficult to do this purely in bash.
See also: bash command to covert html page to a text file

Create a command line script

I'm using a web tool that has inbound webhooks. They provide me with a URL, to which I can POST a string and it logs it into the system.
I would like to create a script that me and my team can use from the terminal to do something like this:
~: appName
~: What is the webHook URL?
Here I can copy and paste the URL gives me, and stores it.
Then from now I can do this:
~: appName This is a message that I want to send...
And this sends as a POST to the webhook the string. This would ideally something I can share with non-techies and that's easy to set up. And I have no idea how to even start this.
I am assuming you want this to be strictly shell.
In the end you want to use something like curl (bash)
curl --data "msg=$2" $url
The $url variable could come from a flat file(app.txt) that is just key value with key=appName
You first script would need to append to the file(app.txt)
echo $1 $2 >> app.txt
This is how you can get started:
#!/bin/bash
msg=$1
url=""
[ ! -f webhookurl ] || url=`cat webhookurl` #webhookurl is a file where you put the url
if [ "$url" == "" ]; then
read -p "What is the webHook URL? " url
echo $url > webhookurl
fi
# Now start posting message
curl --data "msg=$msg" $url
save it with appname. Then run appname like this:
./appname "message to send"
It will ask for url for the first time and save it in webhookurl file in the same folder as the script for future use.

Resources