Skip to content

Examples of using for shell2http

Sergey Mudrik edited this page Sep 30, 2019 · 2 revisions

Clone *.jpg.to service

Get first image from image search

shell2http -cgi / 'curl -Ls https://yandex.ru/images/search\?text=$(echo $PATH_INFO | sed "s/\///") | perl -nE "m/class=.serp-item__thumb.+?src=.(\S+).\s/; say \$1 if \$1" | xargs -I@ curl -Ls https:@'

And get images from http://localhost:8080/cat, http://localhost:8080/dog, http://localhost:8080/github ...

Add CORS header, for get data from another host

shell2http -cgi /data "echo "Access-Control-Allow-Origin: *\n"; echo 'some data for another host'"

Simple static-dir handler

shell2http -cgi /static/ 'file=$(echo $PATH_INFO | sed "s/^\///" | sed "s/\.\.//g"); if [ -d $file ]; then ls -l $file; else cat $file; fi'

Wallpaper generator (with imagemagick)

shell2http -one-thread /wp 'convert -size 2560x1600 plasma:fractal -blur 20x20 -swirl 270 jpg:-'

Markdown viewer

Need blackfriday-tool utility: go get -u github.com/russross/blackfriday-tool

shell2http -cgi /index 'echo "<html><pre>"; ls -l | awk \'$9 ~ /.md$/ {sub("^.+$", "<a href=/page/" $9 ">" $9 "</a>", $9); print}\'' /page/ 'echo "<html>"; blackfriday-tool ${PATH_INFO/\/page\//}'

Custom HTTP-codes in response

shell2http -show-errors -cgi /health './error.sh > /dev/null || echo "Status: 503\n\nError\n"' /ok './ok.sh || echo "Status: 503\n\nError\n"'