Skip to main content

Posts

Showing posts with the label Bash

Notes on daily bash Dec-07 2020

 https://unix.stackexchange.com/questions/42898/find-any-lines-exceeding-a-certain-length Get lines exceeding a certain length. grep '.\{80\}' file perl -nle 'print if length$_>79' file awk 'length>79' file sed -n '/.\{80\}/p' file Get the max length line wc -L brake_input.model.dat Get nth line: sed 'NUMq;d' file If you have NUM in a variable, you will want to use double quotes instead of single: sed "${NUM}q;d" file https://stackoverflow.com/questions/6022384/bash-tool-to-get-nth-line-from-a-file Assuming you need lines 20 to 40, sed -n '20,40p;41q' file_name => not work as expected or awk 'FNR>=20 && FNR<=40' file_name This one work: sed -n -e '10,100p' input.txt > output.txt https://gist.github.com/simofacc/061aaf189a559a0817bf https://stackoverflow.com/questions/13294341/create-slug-to-include-id-and-title-when-insert-record-php-mysql CREATE TRIGGER trigger_name BEFORE INSERT ON tab...

Notes on using ssh-agent with git and other program

ssh-agent bash -c 'ssh-add /somewhere/yourkey; git clone git@github.com:user/project.git' I often used this way few year ago, just noted here. You may have to add sudo somewhere in command above. Use with rsync ssh-agent bash -c 'ssh-add /home/KfW/KEYs/id_rsa; rsync -avz root@123.199.154.222:/var/www/somesite/uploads .' Oh too much (Enable nginx debugging) http://nginx.org/en/docs/debugging_log.html https://serverfault.com/questions/333048/best-way-to-debug-nginx-config-file Nginx image resize on the fly not work.

Bash nohup without output, DB design junction table etc

https://stackoverflow.com/questions/10408816/how-do-i-use-the-nohup-command-without-getting-nohup-out nohup command >/dev/null 2>&1   # doesn't create nohup.out nohup command >/dev/null 2>&1 & # runs in background, still doesn't create nohup.out Job description Requirements: 5 years minimum of professional experience in Software Engineering. Experience with any or all of the following technologies is a plus: Node.js, React, TypeScript. Startup experience valued. Our company: Did you know that 90% of all goods globally are transported through a container, and the largest container vessels are 400 meters long and can transport 20,000 containers at a time? The container shipping industry is the back-bone and enabler of global trade, but it is struggling. At its core the industry is fundamentally inefficient: 50% of all container vessels globally are delayed coming into port, and key planning processes are done manually on a global scale. This...

Mac OSX some key shortcut Android Studio, Sublime Text, show Image dimension size...

Android studio column mode: Alt + Shift + 8, then press All and mouse select for column edit. Press combined above to restore normal mode Sublime Text Ctrl + Shift + Key up/down Damn Magic mouse did not have middle mouse or require 3rd party software to work. Show Image dimension size: In finder view in mode column -> click chose image -> see in right preview area to get size. Or open in Preview then > Menu Edit > Adjust size ... In bash: $ identify photo_.png

Notes on regex sed, bash DOM html, meta tag

Using bash tool sed, awk, grep, vim ... to edit multiple file. Case study DOM tag <html DOCTYPE, meta, charset... https://unix.stackexchange.com/questions/26284/how-can-i-use-sed-to-replace-a-multi-line-string Sed cheatsheet https://gist.github.com/asenchi/2291903 HTML meta tags (recommend way ?) https://www.quackit.com/html_5/tags/html_meta_tag.cfm Example <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml " xml:lang="ja" lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html" charset="EUC-JP" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta name="description" content="content here" ...

Load testing API, LoadImpact, NewRelic, AWS computing, CPU credit, k6 cli...

https://github.com/loadimpact/k6 Price quite high but understandable compared to another service like BrowserStack, New Relic https://loadimpact.com/pricing/#annually Random pop out https://www.techradar.com/news/captcha-if-you-can-how-youve-been-training-ai-for-years-without-realising-it https://stackoverflow.com/questions/28984106/what-is-cpu-credit-balance-in-ec2 https://aws.amazon.com/ec2/instance-types/ Compared to DO smallest 1GB memory, 1CPU (Xeon E520 ? 2.2GHz) https://www.digitalocean.com/pricing/ k6 (loadimpact cli) seem not limit VUs (virtual user) since it run on client machine, use client resources. So cool. But with 1000 vus, even MBP 2017 seem lagging. Digital Ocean cheapest 5$ seem take a while to ready test with 100 vus Auto restart https://forums.aws.amazon.com/thread.jspa?threadID=165405 https://stackoverflow.com/questions/19835455/how-to-restart-node-application-automatically-on-aws-elastic-beanstalk/28986288 My bss suggest use /healthcheck, whe...

Rsync backup data

Tình thế là m có 1 site nhỏ cần backup data upload 1 tuần 1 lần. Data chủ yếu là ảnh, do dịch vụ Amazon S3 chát quá đành quay về dùng trên host. - Ảnh để trong vài thư mục như quiz, answer, post, result ... - Trong các mục trên là các mục con chia theo thời gian upload, vd 2016/01/31 hay 2016/02/14 ... 2016 .......01/ ...........01/ 02/ ... 31/ .......02/ - Backup dùng rsync. - M ko sync cả mục theo tháng là vì dung lượng lớn + với backup theo tuần. Dùng rsync thì đơn giản là copy tất cả mục trong tuần về máy local. Vấn đề là do đường dẫn sync From dài quá nên mình quyên mất là rsync cũng như copy có thể copy nhiều thư mục về 1 chỗ. ví dụ: rsync --ignore-existing --recursive root@188.177.223.224:/var/www/site_release/uploads/post/2016/02/03 . là backup đồng bộ mục ngày 3 tháng 2 về máy local. dễ thấy đường dẫn source là rất dài. Muốn sync nhiều ngày: rsync --ignore-existing --recursive root@188.177.223.224:/var/www/alob_release/uploads/post/2016/02/03  root@188.177....

rsync 1

http://askubuntu.com/questions/323775/monitor-watch-running-rsync-process/323782 You can do: strace -e open $(ps -o lwp= -LC rsync | sed 's/^/-p/') To see what it's doing, or lsof -ad3-999 -c rsync to see what files it currently has opened.

FFmpeg 2

Ghép nhiều video giống nhau (khung hình frame, frame rate fps, cùng codec...)  làm 1. Lệnh sau đây nó tiện hơn do tốc độ xử lý nhanh. https://trac.ffmpeg.org/wiki/Concatenate ffmpeg -f concat -i <(for f in *.wav; do echo "file '$PWD/$f'"; done) -c copy output.wav ffmpeg -f concat -i <(for f in *.wmv; do echo "file '$PWD/$f'"; done) -c copy output.wmv ffmpeg -f concat -i <(for f in *.mp4; do echo "file '$PWD/$f'"; done) -c copy output.mp4 Lưu ý là 2 hay nhiểu video phải same nhau, nếu ko thì output ra sẽ có lỗi ở những video phía sau video đầu tiên. Nó sẽ lấy codec, fps, frame ... của video 1 làm chuẩn. Các video same nhau hay có từ sreencapture, smartphone... nói chung cùng 1 device tạo ra video. Với những video khác thông số thì cần mất công qua nhiều bước hơn, vd: ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts...

Terminal 2

Terminal trên windows: Mặc định khi quét (select) text trên Win thì nó là chọn theo cột (column select) nghĩa là bạn có thể chọn riêng từng cột dữ liệu trên màn hình terminal thay vì chọn hết dòng này đến dòng khác. Trên Windows 10 thì đã đổi về select thông thường nghĩa là bạn quét chữ trên terminal nó sẽ select các dòng liên tục. Nhấn Alt + quét chữ. Trên win cũ thì muốn select các dòng liền mạch thì giữ Ctrl (hay Alt ko nhớ nữa) [ảnh minh họa] Trên Unix default là chọn cả nhiều dòng liên tục khi bạn quét text, muốn chọn cột thì Ctrl + mouse. Trên Win terminal khá tù, muốn tiện lợi thì cài git-bash hay powershell. Giao diện git-bash cũng cần tùy biến cho kích thước to hơn. Copy/Paste Windows: + Enter = copy, Right Click hoặc phím Insert (shift Insert) = Paste. Linux; + Ctrl+shift+C = copy vì Ctrl+C = terminate, dừng chương trình đang chạy. Hơn nữa Ctrl+Shift+C = copy không format dữ liệu (như font, size...) thì phải. + Ctrl + Shift +V = paste vào terminal, lí do là vì...

Ubuntu Server Mail

Some notes when setting ubuntu mail server: guides: 1. Main guide post: https://www.linode.com/docs/email/postfix/email-with-postfix-dovecot-and-mysql 2. other post to understand types and how to setting mail server: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-14-04 http://askubuntu.com/questions/47609/how-to-have-my-php-send-mail List popular MTA and MDA on ubuntu: https://help.ubuntu.com/community/MailServer Automatic tool on github https://github.com/mail-in-a-box Steps: Install postfix (MTA - mail transfer agent) dovecot (a simple MDA - mail deliver agent) sudo apt-get install libsasl2-2 libsasl2-modules sasl2-bin :) Here I'm simulate funny message when King Philip II of Macedon to Thrace: "If I win this war, you will be slaves forever." And You (Thrace) will reply: "If" PHP requires an SMTP client to send mail. You could install a full-featu...