{"id":13393674,"url":"https://github.com/msoap/shell2http","last_synced_at":"2025-04-10T02:15:12.766Z","repository":{"id":28520618,"uuid":"32037384","full_name":"msoap/shell2http","owner":"msoap","description":"Executing shell commands via HTTP server","archived":false,"fork":false,"pushed_at":"2024-12-30T21:52:11.000Z","size":312,"stargazers_count":1396,"open_issues_count":6,"forks_count":138,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-04-10T02:15:00.948Z","etag":null,"topics":["bash","cli","docker","golang","http","proxy","server","shell"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/msoap.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-03-11T19:39:09.000Z","updated_at":"2025-04-09T07:08:15.000Z","dependencies_parsed_at":"2024-01-05T21:46:04.875Z","dependency_job_id":"2ab1deeb-2113-42c0-88f9-d2ba82e4092b","html_url":"https://github.com/msoap/shell2http","commit_stats":{"total_commits":382,"total_committers":5,"mean_commits":76.4,"dds":0.01308900523560208,"last_synced_commit":"e0b5277b5dcf2d6b5f548728d4713bdf4bd36777"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msoap%2Fshell2http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msoap%2Fshell2http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msoap%2Fshell2http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msoap%2Fshell2http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/msoap","download_url":"https://codeload.github.com/msoap/shell2http/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248142902,"owners_count":21054671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","cli","docker","golang","http","proxy","server","shell"],"created_at":"2024-07-30T17:00:58.477Z","updated_at":"2025-04-10T02:15:12.740Z","avatar_url":"https://github.com/msoap.png","language":"Go","readme":"shell2http\n==========\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/msoap/shell2http.svg)](https://pkg.go.dev/github.com/msoap/shell2http)\n[![Go build status](https://github.com/msoap/shell2http/actions/workflows/go.yml/badge.svg)](https://github.com/msoap/shell2http/actions/workflows/go.yml)\n[![Coverage Status](https://coveralls.io/repos/github/msoap/shell2http/badge.svg?branch=master)](https://coveralls.io/github/msoap/shell2http?branch=master)\n[![Report Card](https://goreportcard.com/badge/github.com/msoap/shell2http)](https://goreportcard.com/report/github.com/msoap/shell2http)\n[![Github Releases](https://img.shields.io/github/downloads/msoap/shell2http/total.svg)](https://github.com/msoap/shell2http/releases)\n[![Docker Pulls](https://img.shields.io/docker/pulls/msoap/shell2http.svg?maxAge=3600)](https://hub.docker.com/r/msoap/shell2http/)\n[![Homebrew formula exists](https://img.shields.io/badge/homebrew-🍺-d7af72.svg)](https://github.com/msoap/shell2http#install)\n\n\u003cimg align=\"right\" width=\"128\" height=\"128\" alt=\"shell2http logo\" src=\"https://github.com/msoap/shell2http/assets/844117/d1b56204-2d7e-4ee7-878c-0cbc739e5c68\"\u003e\n\nHTTP-server designed to execute shell commands. It is suitable for development, prototyping or remote control,\nfacilitates rapid iteration and testing of shell-based functionalities.\nEasy to set up using just two command-line arguments: URL-path and shell command.\nNext, when an HTTP request is made for the specified path, the stdout of the shell script will be returned, that's all.\n\nUsage\n-----\n\n    shell2http [options] /path \"shell command\" /path2 \"shell command2\" ...\n    options:\n        -host=\"host\"      : host IP for http server (default bind to all interfaces)\n        -port=NNNN        : port for http server, 0 - to receive a random port (default 8080)\n        -form             : parse query into environment vars, handle uploaded files\n        -form-check       : regexp for check form fields (pass only vars that match the regexp)\n        -cgi              : run scripts in CGI-mode:\n                            - set environment variables with HTTP-request information\n                            - write POST|PUT|PATCH-data to script STDIN (if is not set -form)\n                            - parse headers from script (eg: \"Location: URL\\n\\n\")\n        -export-vars=var  : export environment vars (\"VAR1,VAR2,...\")\n                            by default export PATH, HOME, LANG, USER, TMPDIR\n        -export-all-vars  : export all current environment vars\n        -no-index         : don't generate index page\n        -add-exit         : add /exit command\n        -log=filename     : log filename, default - STDOUT\n        -shell=\"shell\"    : shell for execute command, \"\" - without shell (default \"sh\")\n        -cache=N          : caching command out for N seconds\n        -one-thread       : run each shell command in one thread\n        -show-errors      : show the standard output even if the command exits with a non-zero exit code\n        -include-stderr   : include stderr to output (default is stdout only)\n        -500              : return 500 error if shell exit code != 0\n        -cert=cert.pem    : SSL certificate path (if specified -cert/-key options - run https server)\n        -key=key.pem      : SSL private key path\n        -basic-auth=\"\"    : setup HTTP Basic Authentication (\"user_name:password\"), can be used several times\n        -timeout=N        : set timeout for execute shell command (in seconds)\n        -no-log-timestamp : log output without timestamps\n        -version\n        -help\n\nIn the `-form` mode, variables are available for shell scripts:\n\n  * $v_NNN -- data from query parameter with name \"NNN\" (example: `http://localhost:8080/path?NNN=123`)\n  * $filepath_ID -- uploaded file path, ID - id from `\u003cinput type=file name=ID\u003e`, temporary uploaded file will be automatically deleted\n  * $filename_ID -- uploaded file name from browser\n\nWith `-form-check` option you can specify the regular expression for checking the form fields.\nFor example, if you want to allow only variables that contain the only digits,\nyou can specify the following option: `-form-check='^[0-9]+$'`.\nThen only requests like `http://localhost:8080/path?NNN=123` will be produce variable `$v_NNN`.\n\nTo setup multiple auth users, you can specify the `-basic-auth` option multiple times.\nThe credentials for basic authentication may also be provided via the `SH_BASIC_AUTH` environment variable.\nYou can specify the preferred HTTP-method (via `METHOD:` prefix for path): `shell2http GET:/date date`\n\nInstall\n-------\n\nMacOS:\n\n    brew install msoap/tools/shell2http\n    # update:\n    brew upgrade shell2http\n\nDownload binaries from: [releases](https://github.com/msoap/shell2http/releases/latest) (MacOS/Linux/Windows/RaspberryPi)\n\nFor Docker users, availeble tags see in [Docker Hub](https://hub.docker.com/r/msoap/shell2http):\n\n    docker pull msoap/shell2http\n\nUsing snap (Ubuntu or any Linux distribution with snap):\n\n    # install stable version:\n    sudo snap install shell2http\n    \n    # install the latest version:\n    sudo snap install --edge shell2http\n    \n    # update\n    sudo snap refresh shell2http\n\n*Notice*: the snap-package has its own sandbox with the `/bin`, `/usr/bin` directories which are not equal to system-wide `PATH` directories\nand commands may not work as expected or not work at all.\n\nBuild from source (minimum Go version is 1.12):\n\n    go install github.com/msoap/shell2http@latest\n    # set link to your PATH if needed:\n    ln -s $(go env GOPATH)/bin/shell2http ~/bin/shell2http\n\nCompile for MIPS CPU (for example, for some WiFi routers like Asus):\n\n    GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -trimpath -ldflags=\"-w -s\" -o shell2http .\n\nExamples\n--------\n\n    shell2http /top \"top -l 1 | head -10\"\n    shell2http /date date /ps \"ps aux\"\n    shell2http -export-all-vars /env 'printenv | sort' /env/path 'echo $PATH' /env/gopath 'echo $GOPATH'\n    shell2http -export-vars=GOPATH /get 'echo $GOPATH'\n\n\u003cdetails\u003e\u003csummary\u003eHTML calendar for current year\u003c/summary\u003e\n\n```sh\nshell2http /cal_html 'echo \"\u003chtml\u003e\u003cbody\u003e\u003ch1\u003eCalendar\u003c/h1\u003eDate: \u003cb\u003e$(date)\u003c/b\u003e\u003cbr\u003e\u003cpre\u003e$(cal $(date +%Y))\u003c/pre\u003e\u003c/body\u003e\u003c/html\u003e\"'\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eUsing URL parameters (http://localhost:8080/form?from=10\u0026to=100)\u003c/summary\u003e\n\n```sh\nshell2http -form /form 'echo $v_from, $v_to'\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eCGI scripts\u003c/summary\u003e\n\n```sh\nshell2http -cgi /user_agent 'echo $HTTP_USER_AGENT'\nshell2http -cgi /set 'touch file; echo \"Location: /another_path\\n\"' # redirect\nshell2http -cgi /404 'echo \"Status: 404\"; echo; echo \"404 page\"' # custom HTTP code\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eUpload file\u003c/summary\u003e\n\n```sh\nshell2http -form \\\n    GET:/form 'echo \"\u003chtml\u003e\u003cbody\u003e\u003cform method=POST action=/file enctype=multipart/form-data\u003e\u003cinput type=file name=uplfile\u003e\u003cinput type=submit\u003e\u003c/form\u003e\"' \\\n    POST:/file 'cat $filepath_uplfile \u003e uploaded_file.dat; echo Ok'\n```\n\nTesting by upload file with curl:\n\n    curl -i -F uplfile=@some/file/path 'http://localhost:8080/file'\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eSimple http-proxy server (for logging all URLs)\u003c/summary\u003e\nSetup proxy as \"http://localhost:8080/\"\n\n```sh\nshell2http -log=/dev/null -cgi / 'echo $REQUEST_URI 1\u003e\u00262; [ \"$REQUEST_METHOD\" == \"POST\" ] \u0026\u0026 post_param=\"-d@-\"; curl -sL $post_param \"$REQUEST_URI\" -A \"$HTTP_USER_AGENT\"'\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eTest slow connection (http://localhost:8080/slow?duration=10)\u003c/summary\u003e\n\n```sh\nshell2http -form /slow 'sleep ${v_duration:-1}; echo \"sleep ${v_duration:-1} seconds\"'\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eProxy with cache in files (for debug API with rate limit)\u003c/summary\u003e\nget `http://api.url/` as `http://localhost:8080/get?url=http://api.url/`\n\n```sh\nshell2http -form \\\n    /form 'echo \"\u003chtml\u003e\u003cform action=/get\u003eURL: \u003cinput name=url\u003e\u003cinput type=submit\u003e\"' \\\n    /get 'MD5=$(printf \"%s\" $v_url | md5); cat cache_$MD5 || (curl -sL $v_url | tee cache_$MD5)'\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eRemote sound volume control (Mac OS)\u003c/summary\u003e\n\n```sh\nshell2http /get  'osascript -e \"output volume of (get volume settings)\"' \\\n           /up   'osascript -e \"set volume output volume (($(osascript -e \"output volume of (get volume settings)\")+10))\"' \\\n           /down 'osascript -e \"set volume output volume (($(osascript -e \"output volume of (get volume settings)\")-10))\"'\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eRemote control for Vox.app player (Mac OS)\u003c/summary\u003e\n\n```sh\nshell2http /play_pause 'osascript -e \"tell application \\\"Vox\\\" to playpause\" \u0026\u0026 echo ok' \\\n           /get_info 'osascript -e \"tell application \\\"Vox\\\"\" -e \"\\\"Artist: \\\" \u0026 artist \u0026 \\\"\\n\\\" \u0026 \\\"Album: \\\" \u0026 album \u0026 \\\"\\n\\\" \u0026 \\\"Track: \\\" \u0026 track\" -e \"end tell\"'\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eMock service with JSON API\u003c/summary\u003e\n\n```sh\ncurl \"http://some-service/v1/call1\" \u003e 1.json\nshell2http -cgi /call1 'cat 1.json' /call2 'echo \"Content-Type: application/json\\n\"; echo \"{\\\"error\\\": \\\"ok\\\"}\"'\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eWindows example\u003c/summary\u003e\n\nReturns value of `var` for run in Windows `cmd` (`http://localhost:8080/test?var=value123`)\n\n```sh\nshell2http.exe -form /test \"echo %v_var%\"\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eWith HTTP headers\u003c/summary\u003e\n\nSend custom HTTP headers:\n\n```sh\nshell2http -cgi / 'echo \"Content-Type: application/javascript\\n\"; echo \"{\\\"error\\\": \\\"ok\\\"}\"'\n```\n\nOn Windows:\n\n```sh\nshell2http.exe -cgi / \"echo Content-Type: application/javascript\u0026 echo.\u0026 echo body\"\n```\n\n\u003c/details\u003e\n\n[More examples ...](https://github.com/msoap/shell2http/wiki)\n\nRun from Docker-container\n-------------------------\nExample of `test.Dockerfile` for server for get current date:\n\n```dockerfile\nFROM msoap/shell2http\n# may be install some alpine packages:\n# RUN apk add --no-cache ...\nCMD [\"/date\", \"date\"]\n```\n\nBuild and run container:\n\n    docker build -f test.Dockerfile -t date-server .\n    docker run --rm -p 8080:8080 date-server\n\nIn some cases, such as when multiple shell scripts are running and the main script doesn't wait them properly,\nyou can use `--init` option for `docker run` for prevent zombie processes, see Docker [run reference](https://docs.docker.com/reference/cli/docker/container/run/#init) and about [multiple processes in a container](https://docs.docker.com/engine/containers/multi-service_container/).\n\nSSL\n---\n\nRun https server:\n\n    shell2http -cert=./cert.pem -key=./key.pem ...\n\nGenerate self-signed certificate:\n\n    go run $(go env GOROOT)/src/crypto/tls/generate_cert.go -host localhost\n\nSee also\n--------\n\n * Command-line tool for creating Telegram bot - [shell2telegram](https://github.com/msoap/shell2telegram)\n * A http daemon for local development - [devd](https://github.com/cortesi/devd)\n * Turn any program that uses STDIN/STDOUT into a WebSocket server - [websocketd](https://github.com/joewalnes/websocketd)\n * The same tool configurable via JSON - [webhook](https://github.com/adnanh/webhook)\n","funding_links":[],"categories":["Software Packages","Development","Tools and Plugins","Go","Go Tools","软件包","Downloading and Serving","cli","\u003ca name=\"launcher\"\u003e\u003c/a\u003eCommand launchers","Other Software","軟件包","Go 工具"],"sub_categories":["Other Software","HTTP Server","Windows","Web Development","其他软件","Directory Navigation","其他软件库和软件包","其他軟件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsoap%2Fshell2http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmsoap%2Fshell2http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsoap%2Fshell2http/lists"}