Skip to content

Instantly share code, notes, and snippets.

@cipulan
cipulan / aa-run-before-shutdown.service
Created March 6, 2024 03:16
Run Script Before Reboot, Poweroff, or Terminated
[Unit]
Description=Send Telegram Notif
Requires=network-online.target
After=network.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStop=/usr/bin/bash /opt/script/down.sh
@cipulan
cipulan / wpAutoInstall.sh
Created April 20, 2023 04:54
Automatic Install Wordpress On cPanel Account Creation
#!/bin/bash
TMPFILE="$(mktemp -p /tmp wp-auto-install-XXXXXXXX)"
cat "${1:-/dev/stdin}" > $TMPFILE
DOMAIN=$(python2.7 -c "import sys, json; print json.load(open('$TMPFILE'))['data']['domain']")
CUSTOMEREMAIL=$(python2.7 -c "import sys, json; print json.load(open('$TMPFILE'))['data']['contactemail']")
## The following variable contains the name of the Package that was assigned to the account.
## It would be possible to add additional logic to this script so that WordPress is only installed for certain packages
PACKAGE=$(python2.7 -c "import sys, json; print json.load(open('$TMPFILE'))['data']['plan']")
@cipulan
cipulan / asg-cron.sh
Last active March 7, 2023 08:39
Cron AWS Auto Scaling Group
#!/bin/bash
# Collect some information about this instance
MY_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
MY_REGION=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/.$//')
MY_ASG=$(aws autoscaling describe-auto-scaling-instances --region $MY_REGION --instance-ids $MY_ID --query "AutoScalingInstances[].AutoScalingGroupName" --output text)
# Query the ASG
FIRST_ID=$(aws autoscaling describe-auto-scaling-groups --region $MY_REGION --auto-scaling-group-name $MY_ASG --query "AutoScalingGroups[].Instances[0].InstanceId" --output text)