Skip to content

Instantly share code, notes, and snippets.

@vikbert
Last active July 4, 2018 21:23
Show Gist options
  • Save vikbert/9a80bbd096fc6da0f2e815bc48afd137 to your computer and use it in GitHub Desktop.
Save vikbert/9a80bbd096fc6da0f2e815bc48afd137 to your computer and use it in GitHub Desktop.
[Shell] common used commands and shell snippets #shell, #linux, #command
#!/bin/bash
## switch block
case "$1" in
start)
start
;;
stop)
stop
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
exit 1
esac
# reload bash aliases
source .bashrc
# find processes by name, then kill them one by one
ps aux | grep -ie 'php-fpm' | awk '{print $2}'
ps aux | grep -ie 'php-fpm' | awk '{print $2}' | xargs kill -9
# check if previous command succeed
if [ $? -eq 0 ]; then
echo 'OK'
else
echo 'NOT OK'
fi
# check if input parameter given
if [ $# -eq 0 ]
then
echo "No arguments supplied!"
else
echo "parameter supplied"
fi
# add host alias to /etc/hosts file
echo '172.28.128.10 ubup.docker ubup.dev' | sudo tee -a /etc/hosts
# user management and permission management
# --------------------------------------------------------
# add user with creating home folder
useradd -m gitlab-runner
# assign primary group "nginx" to "gitlab-runner" user
usermod -g nginx gitlab-runner
# list all local user
cut -d: -f1 /etc/passwd
# add a new user
useradd -s /bin/false -d /var/lib/redis -M redis
# show permission current folder
getfacl /srv/www
# file: /srv/www
# owner: gitlab-runner
# group: gitlab-runner
user::rwx
group::rwx
other::r-x
# set basic authentication
touch /etc/nginx/.htpasswd && htpasswd -b /etc/nginx/.htpasswd ubup_shop txfh92s8
# linux clipboard
# --------------------------------------------------------
cat ~/.zsh_aliases | pbcopy
# archive
# --------------------------------------------------------
# create tar file with exclude
tar --exclude='.vagrant' --exclude='./info' --exclude='./stage1' -cvf install.tar ./
# extract archive
tar -xzf bar.tar.gz -C ./my/path
tar -xf shop.tar -C ./www/shop
gzip -c file_to_gzip > new_archive.gz
# scp
# --------------------------------------------------------
# copy local file to remote machine
scp -P 32123 ci.zip xzhou@10.12.180.1:/home/xzhou
# copy remote file to local machine
scp -P 32123 xzhou@stage1:/file/to/send /where/to/put
scp -P 32123 xzhou@sandobx:/var/www/virtual/sandbox.dev.ubup.com/app/config /Users/vikbert/workspace/gitlab/ci/conf
# download
# --------------------------------------------------------
curl -O http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2
# mysql cli
# --------------------------------------------------------
# 10.12.181.9 staging database server with enabled plugin
mysql --enable-cleartext-plugin -h 10.12.181.9 -uxzhou -p
# check if database "ubup" exists
mysqlshow -h 127.0.0.1 -uroot -proot "ubup" > /dev/null 2>&1 && echo "Database ubup exists."
# php|symfony|composer commands
# --------------------------------------------------------
# check symfony requriements
php app/check.php
# check php init where php.ini located
php -i | grep php.ini
# use cache install composer
composer --prefer-dist install
# install/update without any post|pre scripts
composer install --no-plugins --no-scripts
composer update --no-plugins --no-scripts
# config github composer oauth token
composer config -g github-oauth.github.com 4d7530fefa9de23b4bd72eeb411c737ebb9785a1
# redis cli
# --------------------------------------------------------
# connect remote server
redis-cli -h 10.12.182.1 -a EdcoaKrinpa4syavWev9
## symfony parameters.yml
redis_dsn_default: 'redis://securityPassword@10.12.182.*'
# delete multiple keys according to given pattern
for key in `echo 'KEYS shop_de_*' | redis-cli | awk '{print $1}'`; do echo DEL $key; done | redis-cli
for key in `echo 'KEYS shop_doctrine_*' | redis-cli | awk '{print $1}'`; do echo DEL $key; done | redis-cli
# docker commands
# --------------------------------------------------------
# show IP of docker containers
docker inspect -f '{{.Name}} - {{.NetworkSettings.IPAddress }}' $(docker ps -aq)
# start container as backend
docker run -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment