ls -l ./ | sed -n 's~^-.*\(\..*\)$~\1~p' | sort | uniq
find . -empty | wc -l
shell скрипт для автоматического изменения кодировки таблиц и столбцов с utf8 на utf8mb4
#!/bin/bash # mycollate.sh <database> [<charset> <collation>] # changes MySQL/MariaDB charset and collation for one database - all tables and # all columns in all tables DB="$1" CHARSET="$2" COLL="$3" AUTH="-uuser -ppass" [ -n "$DB" ] || exit 1 [ -n "$CHARSET" ] || CHARSET="utf8mb4" [ -n "$COLL" ] || COLL="utf8mb4_general_ci" echo $DB echo "ALTER DATABASE \`$DB\` CHARACTER SET $CHARSET COLLATE $COLL;" | mysql $AUTH echo "USE \`$DB\`; SHOW TABLES;" | mysql -s $AUTH | ( while read TABLE; do echo $DB.$TABLE echo "ALTER TABLE \`$TABLE\` CONVERT TO CHARACTER SET $CHARSET COLLATE $COLL;" | mysql $AUTH $DB done )
https://dba.stackexchange.com/questions/8239/how-to-easily-convert-utf8-tables-to-utf8mb4-in-mysql-5-5
Автоматический перезапуск mariadb если она не активна (Script for checking mariadb status and restarting if it is inactive).
Скрипт:
#!/bin/bash STATUS=$(/bin/systemctl is-active mariadb.service); if [ $STATUS != 'active' ] then /bin/systemctl restart mariadb.service fi
Cron (каждые 5 минут)
*/5 * * * * /var/scripts/check_mariadb.sh
rm -f *
Но, если файлов больше, чем
getconf ARG_MAX
и видим ошибку Argument list too long
, то удалять циклом:
for f in ./*; do rm -f "$f"; done
или find, что более быстро:
find . -delete
Скрипт для загрузки файлов из Google Drive из консоли.
Код скрипта:
#!/bin/bash url=$1 filename=$2 [ -z "$url" ] && echo A URL or ID is required first argument && exit 1 fileid="" declare -a patterns=("s/.*\/file\/d\/\(.*\)\/.*/\1/p" "s/.*id\=\(.*\)/\1/p" "s/\(.*\)/\1/p") for i in "${patterns[@]}" do fileid=$(echo $url | sed -n $i) [ ! -z "$fileid" ] && break done [ -z "$fileid" ] && echo Could not find Google ID && exit 1 echo File ID: $fileid tmp_file="$filename.$$.file" tmp_cookies="$filename.$$.cookies" tmp_headers="$filename.$$.headers" url='https://docs.google.com/uc?export=download&id='$fileid echo Downloading: "$url > $tmp_file" wget --save-cookies "$tmp_cookies" -q -S -O - $url 2> "$tmp_headers" 1> "$tmp_file" if [[ ! $(find "$tmp_file" -type f -size +10000c 2>/dev/null) ]]; then confirm=$(cat "$tmp_file" | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1/p') fi if [ ! -z "$confirm" ]; then url='https://docs.google.com/uc?export=download&id='$fileid'&confirm='$confirm echo Downloading: "$url > $tmp_file" wget --load-cookies "$tmp_cookies" -q -S -O - $url 2> "$tmp_headers" 1> "$tmp_file" fi [ -z "$filename" ] && filename=$(cat "$tmp_headers" | sed -rn 's/.*filename=\"(.*)\".*/\1/p') [ -z "$filename" ] && filename="google_drive.file" echo Moving: "$tmp_file > $filename" mv "$tmp_file" "$filename" rm -f "$tmp_cookies" "$tmp_headers" echo Saved: "$filename" echo DONE! exit 0
Скачиваем скрипт и делаем его исполняемым:
sudo wget -O /usr/sbin/gdrivedl 'https://f.mjh.nz/gdrivedl' sudo chmod +x /usr/sbin/gdrivedl
Варианты использования:
gdrivedl https://drive.google.com/open?id=1sNhrr2u6n48vb5xuOe8P9pTayojQoOc_ gdrivedl https://drive.google.com/file/d/1sNhrr2u6n48vb5xuOe8P9pTayojQoOc_/view?usp=sharing gdrivedl 1sNhrr2u6n48vb5xuOe8P9pTayojQoOc_ gdrivedl https://drive.google.com/open?id=1sNhrr2u6n48vb5xuOe8P9pTayojQoOc_ /tmp/my_file.rar
Источник: https://www.matthuisman.nz/2019/01/download-google-drive-files-wget-curl.html
Зеркало на GitHub: https://github.com/matthuisman/files.matthuisman.nz/blob/master/gdrivedl
Зеркало у себя: gdrivedl
#!/bin/bash cd /var/www/backup/ d=$(date +"%Y_%m_%d") mysqldump --opt -udbuser -pdbpassword dbname | gzip -c -9 > site.ru_$d.sql.gz