nicklasos
10/28/2014 - 4:00 PM

commands, ubuntu, debian, linux, shell, editor

commands, ubuntu, debian, linux, shell, editor

limit_conn_zone $binary_remote_addr zone=addr:10m;
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        #listen 443 ssl http2 default_server;
        #listen [::]:443 ssl http2 default_server;

        #include snippets/ssl-site.com.conf;
        #include snippets/ssl-params.conf;

        root /var/www/site/current/public;

        index index.php index.html;

        server_name site.com;

        client_max_body_size 5m;
        client_body_timeout 5s;
        client_header_timeout 5s;
        limit_conn addr 15;
        limit_req zone=one burst=5;

        location / {
                #limit_except GET {
                #    deny  all;
                #}
                try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

        location ~ /.well-known {
                allow all;
        }
}
# Set vim as default ediotr
sudo update-alternatives --config editor

# Find all files with chmod not 0777
find . -type d \! \( -perm 0777 \)

# Set user
sudo chown -Rh mongodb:mongodb /data/mongodb

# Recur rename file extensions
for X in `find . -name "*.caf"` 
do
 mv $X ${X/.caf/.aac}
done


# count files in folder
find . -type f | wc -l

#set timezone
cp /usr/share/zoneinfo/Europe/Kiev /etc/localtime


# show size of folder in folder
[root@BACKEND]:/var/www/Backend/storage# du -sh ./*
1.8G	./files
4.7G	./offline
11G	./releases
1016M	./screenshots
3.7M	./tmp
1.3G	./trash


#format disk
fdisk -l
cfdisk /dev/sdb
mkfs.ext4 /dev/sdb1
mkdir /disk2
blkid
echo "UUID=359d90df-f17a-42f6-ab13-df13bf356de7 /disk2 ext4 errors=remount-ro 0 1" >> /etc/fstab
mount /disk2

#show config
cat /etc/fstab
UUID=a4ad2b8b-0613-4230-9eb9-a82945cc16cf / ext4 defaults 1 1
UUID=51cc388c-fd08-4182-998f-a4c979648a08 /data xfs defaults,noatime 0 2

#mount
mount -t ext4 /dev/sdc1 /data2


# Run multiple commands in background and terminate all on Ctrl+C
php -S localhost:3001 -t public/ & php -S localhost:3000 -t scripts/proxy/ & redis-server; fg

# group logs by
cat /home/adminroot/.pm2/logs/error.log | grep -oP 'There was an error (.*)'
#!/bin/bash

function valid_ip()
{
    local  ip=$1
    local  stat=1

    if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
        OIFS=$IFS
        IFS='.'
        ip=($ip)
        IFS=$OIFS
        [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
            && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
        stat=$?
    fi
    return $stat
}

# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
   echo "This script must be run as root"
   exit 1
fi

ip=$1
if valid_ip $ip; then {
        sed -i "/DROP/i -A INPUT -s $ip   -i eth0 -m state --state NEW,ESTABLISHED -j ACCEPT" /etc/iptables/rules.v4
        service iptables-persistent reload
        }
        else echo "ERROR: $ip is not a valid IP."
fi
echo $stat                                                                                                                    1,1           All