In this example I'll be installing Apache2 on a Debian VM, but the server can be hosted on any OS or web server capable of serving .sh files.
Installing a Web Server
- Log into the Linux device
- Run the following commands in a terminal window:
# update software repositories
sudo apt update
# install available software updates
sudo apt upgrade -y
# install apache2 webserver and curl
sudo apt install apache2 curl -y
# create a subfolder in the webroot to store .sh files
sudo mkdir /var/www/html/bash -p
Creating a Sample Bash Script
- Continue with the following command to create a sample bash script
sudo nano /var/www/html/bash/whoami.sh
- Paste the following script into whoami.sh
#!/bin/bash
echo "hello, today is $(date '+%A'). You are running me as $(whoami)." - Press CTRL+O, Enter, CTRL+X to write the changes to whoami.sh
Executing the Sample Bash Script
- Continue with the following command to execute the sample script
curl http://DNSorIP/bash/whoami.sh | bash