• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

Run Shell Script From Your Website

September 10, 2019

Here’s how to run a shell script from your website. You’ll need 2 files.

Here’s the contents of foo.php. Wrap your output with ‘pre’ for better formatting.

<?php
$output = shell_exec('/var/www/html/bar.sh 2>&1');
echo "$output";

<?php $output = shell_exec('/var/www/html/bar.sh 2>&1'); echo "$output";

Here’s the content of bar.sh. Output will be displayed on web page.

#!/bin/bash
now="$(date +'%y%m%d')"
echo $now
aws s3 ls

#!/bin/bash now="$(date +'%y%m%d')" echo $now aws s3 ls

Filed Under: Cloud, Linux Tagged With: bash, php, run, script, shell, website

Search This Website

Subscribe Via Email

  • Home
  • About
  • Archives

Copyright © 2023