From 6bc7a961ced0ae92c4fe550ade547500f17251fc Mon Sep 17 00:00:00 2001 From: alifeee Date: Tue, 12 Nov 2024 23:30:37 +0000 Subject: [PATCH] uploaded serving a random image with a CGI script.md --- ...erving a random image with a CGI script.md | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 notes/serving a random image with a CGI script.md diff --git a/notes/serving a random image with a CGI script.md b/notes/serving a random image with a CGI script.md new file mode 100644 index 0000000..85bee84 --- /dev/null +++ b/notes/serving a random image with a CGI script.md @@ -0,0 +1,27 @@ +--- +date: 2024-11-12 +title: serving a random image with a CGI script +tags: cgi +--- +I made this because I have hundreds of images of myself and what I have been doing from BeReal. + +I stopped using it because the company got big and evil (booo), so I requested all my data (images) and I (will soon) request them to remove that data. + +But, for the meanwhile, I've been screwing around with it. I made a timelapse, but also fun is a random image picker. + +I put all the images on my server, and made a very simple CGI script: + +```bash +#!/bin/bash + +file=$( (cd /var/www/; find images/ -type f -not -name "*index.html" \ + | sort --random-sort | head -n1) ) + +echo "HTTP/1.1 302 Found" +echo "Location: /${file}" +echo "" +``` + +now I can access `/.../random.cgi` and it redirects me to an image, served by nginx. Sweet. + +I would like to write a bigger blog about CGI scripts in future.