# Folder for CGI scripts
$ mkdir ~/html/cgi-bin
# Create file such a this
$ cat ~/html/cgi-bin/foo.cgi
#!/usr/bin/bash
echo 'Content-type: text/html'
echo ''
echo ''
echo ''
echo ''
echo ''
echo ''
echo 'Hello World!
'
echo ''
echo "Query (after '?' in the URL): ${QUERY_STRING}"
echo "From: ${HTTP_USER_AGENT}"
echo '
'
echo ''
echo ''
exit 0
# Set executable attribute
$ chmod +x foo.cgi
# Set secure web permissions
$ mkhomepg
setting secure web permissions for /meta/www/h/hangar118
% queing permissions to be set
# Correct permissions would look like this
$ ls -l ~/html/cgi-bin/
total 4.0K
-rwxr-x--- 1 hangar118 www-data 368 Jan 3 02:21 foo.cgi*
It can be invoked via https://hangar118.sdf.org/cgi-bin/foo.cgi?a=1;b=2
Then, in the browser it will produce an output similar to this:
Hello World!
Query (after '?' in the URL): a=1;b=2
From: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0
NOTE: The example session is from the MetaArray