Archive for the ‘bash’ Category

Docker how-to add extra port to current container

$ docker run -d -t -p 81:80 -v /home/imran/Projects/tmptmp:/var/www/html –name mycontainer ubuntu:latest /bin/bash $ docker stop mycontainer $ docker commit mycontainer mydockerimage $ docker rm mycontainer $ docker run -d -t -p 81:80 -p 444:443 -v /home/imran/Projects/tmptmp:/var/www/html –name mycontainer myusername/mydockerimage:latest /bin/bash

php exec debugging no stdout and stderr output

try this exec(’some_unkown_command 2>&1′, $output); print_r($output);

Access ssh via key in command line

ssh username@servername.com -i your_private_key

Find files owned by specific user

find /path -user www-data -print

Rename files in folder

for i in *.png; do mv "$i" "${i/.png/t.png}"; done

Run command on Ubuntu startup as superuser

vi /etc/rc.local

Dig to query specific dns server

dig mydomain.com @ns.myserver.com

Awk Insert into table

cat file.csv | awk -F, ‘{print "INSERT INTO mytable VALUES ("$1",*"$2"*,"$3");"}’ echo https://api.trustpilot.com/tagname/tags | awk -F/ ‘{print $2}’

Grep show next or previous line when for matched value

Show next line after matched line grep -A1 searchpattern filename Show next 2 lines after matched line grep -A2 searchpattern filename Show previous line after matched line grep -B1 searchpattern filename

Ssh tunnel

Random port tunnelling using a private key: #!/bin/sh   ssh -L 5446:hostname:5446 -i /home/imran/Servers/iaghayev iaghayev@192.168.1.10 -p 2222 Mysql port tunnelling using a private key: #!/bin/sh   ssh -L 3309:127.0.0.1:3306 -i /home/imran/Servers/iaghayev iaghayev@192.168.1.10 -p 2222