Skip to content

Instantly share code, notes, and snippets.

View MattLoyeD's full-sized avatar
🎯
Focusing

Matthieu D MattLoyeD

🎯
Focusing
View GitHub Profile
@MattLoyeD
MattLoyeD / cron_checkup.sh
Created August 27, 2016 11:44
Check website availability then reboot services if needed
#runs a check of your website http code response (Bad gateway, empty response, or service off) every half minute then send sms if reboot via Free Mobile API
jobjob()
{
var=`curl -I http://www.zogzog.com/ 2>/dev/null | head -n 1 | awk -F" " '{print $2}'`
if [[ -z "$var" ]] || [ "$var" == "502" ] || [ "$var" == "324" ]
then
curl -I "https://smsapi.free-mobile.fr/sendmsg?user=___&pass=___&msg=$var%20Serv%20Autorestart%20!";
sudo service nginx restart; sudo service php7.0-fpm restart;
@MattLoyeD
MattLoyeD / super_backup.php
Last active January 29, 2016 18:11
Local to ftp backup (sql & files, limited by local or ftp timestamp or folder/file sizes).
<?php
$conf = array(
"backup_prefix" => "bc-",
"backup_dir" => dirname(__FILE__).'/backups/',
"backup_files" => true,
"backup_target_dir" => '/folder',
"keep_local_files" => true,
"local_backup_size_limit" => "80GB", // in what you want, like 1GB or 2MB
"local_backup_time_limit" => 7, // in days, 0 for no limit
@MattLoyeD
MattLoyeD / cron_save_sql_ftp.sh
Created July 18, 2013 10:15
Cron SH file to save your SQL and export the backup to an FTP. Script can remove files older than X (7 here) days on localhost. All files and folder must be chmod 777 for convinience. Including this.
#!/bin/bash
echo "SQL Backup in Progress"
#Date
NOWDATE=`date '+%H%M-%m-%d-%Y'`
# your MySQL server's name
SERVER=domain.com
@MattLoyeD
MattLoyeD / linux_shell_basic_commands.sh
Last active December 19, 2015 22:29
Linux Shell Basic Commands
# Find all files heavier >20M / human readable
find / -type f -size +20M -exec ls -lh {} \; | awk '{ print $NF ": " $5 }'
# Find all heavy folders
du -sh /*
# OR
du -h | sort -h
# Silent Curl for cron ?
curl --silent http://domain.com/cron.php
@MattLoyeD
MattLoyeD / cron_save_files_ftp.sh
Created July 18, 2013 10:10
Cron SH file to save your site and export the backup to an FTP. Script can remove files older than X (7 here) days on FTP and on localhost. All files and folder must be chmod 777 for convinience. Including this.
#!/bin/bash
echo "Backup in progress"
nowdate=`date '+%H%M-%m-%d-%Y'`
# your MySQL server's name
SERVER=domain.com
@MattLoyeD
MattLoyeD / cron_img.sh
Last active December 14, 2015 14:33
Image Optimizer for web (PNG & Jpg) Losslesly
#! /bin/sh
# Usage "sh script.sh /path/to/check chmod"
# TODO : Mtime in find ...
if [ -z "$1" ]; then
DIR="`.`"
else
DIR="$1"
fi
@MattLoyeD
MattLoyeD / cron_mp3.sh
Created October 28, 2015 15:19
Copy new music files to a folder
#!/bin/bash
extarray=( mp3 flac ogg wmv wav ) ;
HOME=$1;
DESTINATION=$2;
#if [ $HOME == "/" || $HOME == $DESTINATION ] { exit 1 }
cd $HOME;
@MattLoyeD
MattLoyeD / clamav_autoscan.sh
Last active October 28, 2015 15:17
Clamav autoscan + Email alert
#!/bin/bash
# Usage "sh script.sh /path/to/check"
if [ -z "$1" ]; then
vir_dir="`./virus`"
else
vir_dir="$1"
fi
mails=mail@domain.tld;
@MattLoyeD
MattLoyeD / substr_paragraph.php
Last active August 29, 2015 14:27
Easy substr for paragraph in PHP
<?php
function substr_paragraph($string, $length = 520, $html = false) {
$pos = strpos($string, "</p>",$length);
$tag_len = 4;
if(empty($pos)){
$pos = strpos($string, "</div>",$length);
$tag_len = 5;
@MattLoyeD
MattLoyeD / remove_from_git_based_on_gitignore.sh
Created July 21, 2015 23:56
Remove files from git based on gitignore
git ls-files -i -z --exclude-from=.gitignore | xargs -0 git rm --cached