Force Umount if Busy

If device is busy and you can’t umount it, try it with -l option (lazy unmount). Or you can force it.

# standard
umount /mnt/data
# lazy umount
umount -l /mnt/data
# force
umount -f /mnt/data

Lazy unmount is safer since it will detach immediately and clean up all references to the file system. Force is a bit more drastic.

Run Shell Script From Your Website

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";

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

Phpinfo Blank Page

Here’s how to fix when phpinfo is displaying a blank page. The install is missing this php module.

apt install php libapache2-mod-php

Restart after install.

service apache2 restart

AWS Security Groups IP Cidr

Here’s how to search for AWS Security Groups containing this IP Cidr.

aws ec2 describe-security-groups \
--filter Name=egress.ip-permission.cidr,Values='10.8.8.8/32' \
--query "SecurityGroups[*].{Name:GroupName}" \
--output text \
--profile default \
--region us-east-1

Search with ports.

aws ec2 describe-security-groups \
--filter Name=egress.ip-permission.cidr,Values='10.8.8.8/32' \
         Name=egress.ip-permission.from-port,Values='22' \
         Name=egress.ip-permission.to-port,Values='22' \
--query "SecurityGroups[*].{Name:GroupName}" \
--output text \
--profile default \
--region us-east-1

Query will only display the Security Group name.