sh 贝壳铃声

贝壳铃声

s.sh
# get the 20 most used commands
# https://github.com/trimstray/the-book-of-secret-knowledge#tool-terminal

history | \
awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | \
grep -v "./" | \
column -c3 -s " " -t | \
sort -nr | nl |  head -n 20

# kill process running on port <port> 
kill -9 $(lsof -i :<port> | awk '{l=$2} END {print l}')

# find last reboot time
who -b

# show 20 biggest directories with K M G
du | \
sort -r -n | \
awk '{split("K M G",v); s=1; while($1>1024){$1/=1024; s++} print int($1)" "v[s]"\t"$2}' | \
head -n 20

sh png到jpg白色背景

png2jpg.sh
convert png.png -background white -flatten  jpg.jpg

sh setup-headless-selenium-xvfb.sh

setup-headless-selenium-xvfb.sh
#!/bin/bash
#
# Bash script to setup headless Selenium (uses Xvfb and Chrome)
# (Tested on Ubuntu 12.04) trying on ubuntu server 14.04

# Add Google Chrome's repo to sources.list
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" | sudo tee -a /etc/apt/sources.list

# Install Google's public key used for signing packages (e.g. Chrome)
# (Source: http://www.google.com/linuxrepositories/)
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -

# Update apt sources:
sudo apt-get update

# Install Python, pip, Selenium:
#sudo apt-get -y install python python-pip
#sudo pip install selenium
different way to get chromedriver and selenium java jar:
sudo apt-get -y install default-jre  # if not installed yet
sudo npm install protractor -g
sudo webdriver-manager update
sudo ln /usr/lib/node_modules/protractor/selenium/chromedriver /usr/bin/chromedriver
#sudo apt-get -y install unzip
# Download/Install chromedriver
# (http://code.google.com/p/chromedriver/):
#
# For x86:
#wget -c http://chromedriver.googlecode.com/files/chromedriver_linux32_2.1.zip
#unzip chromedriver_linux32_2.1.zip
#
# For x86-64:
#wget -c http://chromedriver.googlecode.com/files/chromedriver_linux64_2.1.zip
#unzip chromedriver_linux64_2.1.zip
# Neither creating symbolic link nor adding dir to $PATH worked for me
# in a Vagrant VM. So, let's blatantly copy the binary:
#sudo cp ./chromedriver /usr/bin/
#sudo chmod ugo+rx /usr/bin/chromedriver

# Install Google Chrome:
sudo apt-get -y install libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4
sudo apt-get -y install google-chrome-stable

# Dependencies to make "headless" chrome/selenium work:
sudo apt-get -y install xvfb gtk2-engines-pixbuf
sudo apt-get -y install xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable

# Optional but nifty: For capturing screenshots of Xvfb display:
sudo apt-get -y install imagemagick x11-apps

# Make sure that Xvfb starts everytime the box/vm is booted:
echo "Starting X virtual framebuffer (Xvfb) in background..."
Xvfb -ac :99 -screen 0 1280x1024x16 &
export DISPLAY=:99

# Optionally, capture screenshots using the command:
#xwd -root -display :99 | convert xwd:- screenshot.png

sh su GitHub(从给定用户下载所有存储库)

su GitHub(从给定用户下载所有存储库)

sugh.sh
#!/bin/bash

if [ -z "$1" ]; then
    echo "waiting for the following arguments: username + max-page-number"
    exit 1
else
    name=$1
fi

if [ -z "$2" ]; then 
    max=2
else
    max=$2
fi

cntx="users"
page=1

echo $name
echo $max
echo $cntx
echo $page

until (( $page -lt $max ))
do 
    curl "https://api.github.com/$cntx/$name/repos?page=$page&per_page=100" | grep -e 'git_url*' | cut -d \" -f 4 | xargs -L1 git clone
    $page=$page+1
done

exit 0

sh 清除Android的状态栏

清除Android的状态栏

adb-demo.sh
#!/bin/sh

# source: https://android.jlelse.eu/clean-your-status-bar-like-a-pro-76c89a1e2c2f
# Add these aliases to your `~/.profile`
# alias demoOn='sh /Users/<username>/scripts/adb-demo.sh on'
# alias demoOff='sh /Users/<username>/scripts/adb-demo.sh off'

CMD=$1

if [[ $CMD != "on" && $CMD != "off" ]]; then
  echo "Usage: $0 [on|off]" >&2
  exit
fi

adb shell settings put global sysui_demo_allowed 1 

if [ $CMD == "on" ]; then
  // display time 11:10
  adb shell am broadcast -a com.android.systemui.demo -e command clock -e hhmm 1110

  // Display full mobile data without type
  adb shell am broadcast -a com.android.systemui.demo -e command network -e mobile show -e level 4 -e datatype false

  // Hide notifications
  adb shell am broadcast -a com.android.systemui.demo -e command notifications -e visible false

  // Show full battery but not in charging state
  adb shell am broadcast -a com.android.systemui.demo -e command battery -e plugged false -e level 100
elif [ $CMD == "off" ]; then
  adb shell am broadcast -a com.android.systemui.demo -e command exit
fi

sh [shell]编辑主机文件

edit_hosts_file.sh
sudo nano /etc/hosts

sh [域名检查]域名dns,记录#domain

[域名检查]域名dns,记录#domain

domain-test.sh
nslookup -type=cname yourdomain.com

sh Azure命令备忘单

az-account-commands.sh
az account list
az account set --subscription <guid taken from above>

az account show --query "{subscriptionId:id, tenantId:tenantId}"

sh psql-cheatsheet.md

psql-cheatsheet.md
// Remote Access PSQL
```bash
psql --host=host --port=5432 --username=username@servername --dbname=postgres
```

// create user
```bash
sudo -u postgres createuser <username>
```

// create database
```bash
sudo -u postgres createdb <dbname>
```

// grant privilleges
```bash
sudo -u postgres psql
psql=# alter user <username> with encrypted password '<password>';
```

// from psql
```bash
CREATE DATABASE yourdbname;
CREATE USER youruser WITH ENCRYPTED PASSWORD 'yourpass';
GRANT ALL PRIVILEGES ON DATABASE yourdbname TO youruser;
```
connectdb.sh
psql -p 5432 -h localhost -U postgres
psql-console.sh
#check size db
SELECT pg_size_pretty( pg_database_size('ppda_datalake'));

#
remote-access.sh
#postgresql.conf
listen_addresses = '*' 

#pg_hba.conf
host all all 0.0.0.0/0 md5

sh 查找云端服务器上的所有访问日志,并将它们合并为一个输出

find-and-output-access-logs.sh
# Run from /home/master/applications
# dumps everything to the screen
find . -maxdepth 3 -path '*/logs/*access*.log' -exec cat {} +

# Run from /home/master/applications
# continuously outputs everything to the screen. Shows headings for each file that's outputting
ls -drt */logs/*access*.log | tail -n5 | xargs tail -n0 -f

# Run from /home/master/applications
# outputs to file: /home/master/access-logs-all.log
find . -maxdepth 3 -path '*/logs/*access*.log' -exec cat {} + > ~/access-logs-all.log

# Run from /home/master/applications
# outputs to file: /home/master/access-logs-all.log
find . -maxdepth 3 -path '*/logs/*error*.log' -exec cat {} + > ~/error-logs-all.log