Skip to content

Instantly share code, notes, and snippets.

View saderi's full-sized avatar
🦇

Payam Saderi saderi

🦇
View GitHub Profile
@saderi
saderi / image-cleanup.sh
Created December 12, 2023 13:01
This script will delete all but the last 5 versions of a docker image from the local machine (not from the registry)
#!/bin/bash
IMAGE_NAME=$1
VERSIONS_TO_KEEP=5
TOTAL_VERSIONS=$(docker image ls | grep $IMAGE_NAME | grep -v latest | wc -l)
VERSIONS_TO_DELETE=$((TOTAL_VERSIONS - VERSIONS_TO_KEEP))
if [ $VERSIONS_TO_DELETE -gt 0 ]; then
echo "Deleting $VERSIONS_TO_DELETE old versions"
docker image ls | grep $IMAGE_NAME | grep -v latest | tail -n $VERSIONS_TO_DELETE | awk '{print $3}' | xargs docker image rm
#!/bin/bash
# This script is used to install node_exporter on linux amd64 platform.
# You can run this script directly with the following command, or you can download and run it.
# curl -fsSL https://gist.githubusercontent.com/saderi/ea80dd490badc6ab96603130507e1c97/raw | bash -
set -e
NODE_EXPORTER_VERSION="1.6.1"
#!/bin/bash
# Run the following command on server
# eval "$(curl -fsSL https://gist.githubusercontent.com/saderi/85063e551adcb2e3f6125aee889f36f6/raw/public_alias)"
function xpass() {
[ -z "$2" ] && LENGTH=30 || LENGTH=$2
[ -z "$3" ] && CHAR='[:alnum:]#$@^%&' || CHAR='[:alnum:]'
@saderi
saderi / vesta_cp_db_backup.sh
Last active April 17, 2024 15:59
Backup all databases in vestacp server
#!/bin/bash
## Creating a backup user, we will create a backup user with the minimum permissions necessary to run mysqldump
# CREATE USER 'backupuser'@'localhost' IDENTIFIED BY 'p455w0rd';
# GRANT SELECT, SHOW VIEW, LOCK TABLES, RELOAD, REPLICATION CLIENT ON *.* TO 'backupuser'@'localhost';
# FLUSH PRIVILEGES;
DB_USERNAME=backupuser
DB_PASSWORD=p455w0rd
#!/bin/bash
# This script is meant for quick & easy install via:
# Tested in debian 9
# $ wget -q -O - "https://gist.github.com/saderi/af196e947b5f913a32e188d901975f0e/raw" | bash -
# install apache, mysql
apt-get update \
&& apt-get install -y curl vim git ca-certificates apt-transport-https gnupg && \
apt-get install -y apache2 mariadb-server
auth_param basic program /usr/lib/squid3/basic_ncsa_auth /etc/squid/squid_passwd
auth_param basic children 5
auth_param basic realm Proxy Authentication Required
auth_param basic credentialsttl 2 hours
auth_param basic casesensitive off
acl auth_users proxy_auth test
http_access allow auth_users
#!/bin/bash
# This script is meant for quick & easy install via:
# Tested in Ubuntu 18.10
# $ wget -q -O - "https://bit.ly/2tlAk9r" | bash -
apt update && apt install --assume-yes gnupg2
tee /etc/apt/sources.list.d/mongodb-org-4.0.list << EOF
#!/bin/bash
# This script is meant for quick & easy install via:
# Tested in debian 9
# $ wget -q -O - "https://saderi.com/getready" | bash -
# Update , upgrade OS and install curl, vim and git
apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt install -y curl vim
#!/bin/bash
RIGHTNOW=$(date +"%Y-%m-%d-%H%M");
OLD_BACKUP=$(date --date="4 days ago" +"%Y-%m-%d");
FTP_HOST=''
FTP_USER=''
FTP_PASSWORD=''
DB_NAME=''
DB_USERNAME=''
#!/bin/bash
# Add my ssh-key to ubuntu root user and active ssh root login
# Login as root or run with sudo
# wget -qO - "https://saderi.com/goroot" | bash -
# OR
# curl -fsSL https://saderi.com/goroot | bash -
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"