{"id":181,"date":"2017-11-07T00:13:24","date_gmt":"2017-11-06T23:13:24","guid":{"rendered":"http:\/\/xpam.pl\/blog\/?p=181"},"modified":"2024-04-03T00:48:28","modified_gmt":"2024-04-02T22:48:28","slug":"bashmagic-collection-vol1","status":"publish","type":"post","link":"https:\/\/xpam.pl\/blog\/?p=181","title":{"rendered":"Bashmagic collection vol1"},"content":{"rendered":"<p>Keep only last X lines of a file (shrink).<\/p>\n<pre><code class=\"language-bash\">echo &quot;$(tail -n 10000 huge.log)&quot; &gt; huge.log<\/code><\/pre>\n<p>Deploy maven artefact to a specific repo without specifying it in pom.xml (format <strong>repoId:default:repoUrl<\/strong>). Repo should be specified in your .m2 settings.xml with any necessary credentials.<\/p>\n<pre><code class=\"language-bash\">mvn deploy -DaltDeploymentRepository=repo.mydomain.com.my.releases::default::https:\/\/repo.mydomain.com\/repository\/maven-my-releases\/<\/code><\/pre>\n<p>One liner to set password for default PostgreSQL user after initial install.<\/p>\n<pre><code class=\"language-bash\">runuser -l postgres -c $&#039;psql -c &quot;ALTER USER postgres WITH PASSWORD \\&#039;postgres\\&#039;;&quot;&#039;<\/code><\/pre>\n<p>Run command inside a screen and save all output to a file<\/p>\n<pre><code class=\"language-bash\">screen -dm bash -c &#039;script -c &quot;some chatty command&quot; output.txt&#039;<\/code><\/pre>\n<p>Scroll around inside a screen.<\/p>\n<pre><code class=\"language-bash\">screen -r myscreen\n\nctrl+a\n\n[\n\nctrl+u and ctrl+d for up and down. bufer is limited<\/code><\/pre>\n<p>Add 4GB swap on Centos 7 with a stroke of a copy-paste.<\/p>\n<pre><code class=\"language-bash\">sudo dd if=\/dev\/zero of=\/swapfile count=4096 bs=1MiB\nsudo chmod 600 \/swapfile\nsudo mkswap \/swapfile\nsudo swapon \/swapfile\necho &#039;\/swapfile none swap sw 0 0&#039; | sudo tee -a \/etc\/fstab<\/code><\/pre>\n<p>Standard tcpdump.<\/p>\n<pre><code class=\"language-bash\">tcpdump -i eth0 -s 65535 -w dump.pcap<\/code><\/pre>\n<p>Show listening ports with corresponding executables.<\/p>\n<pre><code class=\"language-bash\">netstat -tulpn<\/code><\/pre>\n<p>Show systemd logs for a specific service.<\/p>\n<pre><code class=\"language-bash\">journalctl -u nginx.service<\/code><\/pre>\n<p>Freshly installed nginx configured as reverse proxy on Centos 7 getting \"Permission denied\" when connecting to backend service<\/p>\n<pre><code class=\"language-bash\">setsebool -P httpd_can_network_connect 1<\/code><\/pre>\n<p>Convert a certificate stored in a Java keystore to a PEM cert and key (for example, Tomcat to Nginx transition).<\/p>\n<pre><code class=\"language-bash\">$JAVA_HOME\/bin\/keytool -importkeystore -srckeystore .keystore -destkeystore keystore.p12 -deststoretype PKCS12 -srcalias mycrtalias -deststorepass changeit -destkeypass changeit\nopenssl pkcs12 -in keystore.p12 -nokeys -out cert.pem\nopenssl pkcs12 -in keystore.p12 -nodes -nocerts -out key.pem<\/code><\/pre>\n<p>Disable git SSL verification per-repo.<\/p>\n<pre><code class=\"language-bash\">git config http.sslVerify &quot;false&quot;<\/code><\/pre>\n<p>Disable git SSL verification at clone time.<\/p>\n<pre><code class=\"language-bash\">git -c http.sslVerify=false clone something<\/code><\/pre>\n<p>Clear git username and password cache for a repo (in case of password change or similar).<\/p>\n<pre><code class=\"language-bash\">git config --global --unset user.password<\/code><\/pre>\n<p>Give user sudo privileges.<\/p>\n<pre><code class=\"language-bash\">sudo usermod -aG wheel &lt;user&gt;<\/code><\/pre>\n<p>Git submodule is added to an existing repo and is not resolving for you locally.<\/p>\n<pre><code class=\"language-bash\">git submodule update --init --recursive<\/code><\/pre>\n<p>Print all TCP connections of a Docker container.<\/p>\n<pre><code class=\"language-bash\">sudo docker inspect -f &#039;{{.State.Pid}}&#039; containerName\n&lt;result&gt;\nsudo nsenter -t &lt;result&gt; -n netstat<\/code><\/pre>\n<p>Nmap portscan.<\/p>\n<pre><code class=\"language-bash\">sudo nmap -p 1-65535 -sV -sS -T4 &lt;ip&gt;<\/code><\/pre>\n<p>Force JVM to use \/dev\/urandom instead of \/dev\/random (sometimes needed in low entropy environments like Docker).<\/p>\n<pre><code class=\"language-bash\">java -Djava.security.egd=file:\/dev\/.\/urandom ...<\/code><\/pre>\n<p>Debug print all network activities on JVM level.<\/p>\n<pre><code class=\"language-bash\">java -Djavax.net.debug=all ...<\/code><\/pre>\n<p>Create .htpasswd file for Nginx<\/p>\n<pre><code class=\"language-bash\">sudo sh -c &quot;echo -n &#039;someuser:&#039; &gt;&gt; \/etc\/nginx\/.htpasswd&quot;\nsudo sh -c &quot;openssl passwd -apr1 &gt;&gt; \/etc\/nginx\/.htpasswd&quot;<\/code><\/pre>\n<p>Do or do not do something if file was modified recently<\/p>\n<pre><code class=\"language-bash\">RECENTLY_CHANGED=$(find \/tmp\/me -newermt &#039;10 minutes ago&#039; |wc -l |xargs)\nif [ &quot;$RECENTLY_CHANGED&quot; -eq 1 ]; then\n    echo &quot;File was changed recently, terminating script&quot;\n    exit 0\nfi<\/code><\/pre>\n<p>&nbsp;<\/p>\n<div class=\"wp-post-signature\">\r\n<br \/>\r\n<br \/>\r\n<img src='https:\/\/xpam.pl\/aaaaff.png' title='Moonie' \/> Cen<br \/>\r\n<a href='https:\/\/github.com\/cen1'>GitHub<\/a><br \/>\r\n<a href='https:\/\/eurobattle.net'>Eurobattle.net<\/a><br \/>\r\n<a href='https:\/\/lagabuse.com'>Lagabuse.com<\/a><br \/>\r\n<a href='https:\/\/bnetdocs.org'>Bnetdocs<\/a><br \/>\r\n<\/div>\r\n","protected":false},"excerpt":{"rendered":"<p>Keep only last X lines of a file (shrink). echo &quot;$(tail -n 10000 huge.log)&quot; &gt; huge.log Deploy maven artefact to a specific repo without specifying it in pom.xml (format repoId:default:repoUrl). Repo should be specified in your .m2 settings.xml with any necessary credentials. mvn deploy -DaltDeploymentRepository=repo.mydomain.com.my.releases::default::https:\/\/repo.mydomain.com\/repository\/maven-my-releases\/ One liner to set password for default PostgreSQL user after [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,18],"tags":[23],"class_list":["post-181","post","type-post","status-publish","format-standard","hentry","category-linux","category-script-magic","tag-bashmagic"],"_links":{"self":[{"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts\/181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=181"}],"version-history":[{"count":14,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts\/181\/revisions"}],"predecessor-version":[{"id":539,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts\/181\/revisions\/539"}],"wp:attachment":[{"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}