tag:blogger.com,1999:blog-190230612024-03-12T23:39:55.226+00:00Wawrzyniec NiewodniczaĆski in EnglishKind of my extended memory with thoughts mostly on Linux and related technologies. You might also find some other stuff, a bit of SF, astronomy as well as old (quantum) chemistry posts.Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.comBlogger198125tag:blogger.com,1999:blog-19023061.post-32960208037084419852024-02-04T22:36:00.001+00:002024-02-05T09:17:16.113+00:00Open file from command line (in Linux and Macos)<p>One of the nice feature of MacOS is the <b>open</b> command. It allows opening files directly from the command line without knowing the application linked to the file type. For example: </p><p> <span style="font-family: courier;"><b>open interesting.pdf</b></span> </p><p>opens the interesting.pdf file using whatever program is assigned to open PDF files. (If you want more example about the open command, you can check this <a href="https://scriptingosx.com/2017/02/the-macos-open-command/" rel="nofollow" target="_blank">link</a>.)</p><p>For some time I wonder about a Linux equivalent. Recently decided to look for it more actively and check if AI might help. It did, and pointed at the <b><a href="https://manpages.ubuntu.com/manpages/focal/man1/gio.1.html" rel="nofollow" target="_blank">gio</a></b> command from the <a href="https://en.wikipedia.org/wiki/GIO_(software)" rel="nofollow" target="_blank">Gnome Input/Output</a> library. After adding a function or an alias following block of code to the .zshrc, I have a Linux equivalent.</p><ul style="text-align: left;"><li> alias</li></ul><p><b>open="gio open" </b><br /></p><ul style="text-align: left;"><li>function: </li></ul><p><span style="font-family: courier;"><b>open () {</b></span></p><p><span style="font-family: courier;"><b><span> </span><span>gio open $1</span></b></span></p><p><span style="font-family: courier;"><b><span>} </span> </b></span><br /></p><p>And finally, xdg-open is an alternative for the "gio open".<br /></p>Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-54650401209989631652023-12-30T21:47:00.004+00:002023-12-30T21:47:49.017+00:00Glow the Grip of MD files (from GitHub)<p>If you will every need to locally render an MD file, e.g. reading some documentation, you can use the <b>glow</b> [1] program. It renders a MD file in the terminal.</p><p>In the case of GitHub repository, an alternative is to use the <b>grid</b> [2] project. It sets a local webserver using the GitHub markdown API. It produces a local view of MD files as they would be in the GitHub website.<br /></p><p> </p><h4 style="text-align: left;">Links <br /></h4><ol style="text-align: left;"><li>https://github.com/charmbracelet/glow </li><li>https://github.com/joeyespo/grip</li></ol>Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-52698745313908314652023-11-12T23:21:00.007+00:002023-11-12T23:22:50.104+00:00Summary of a Terraform plan output<p>One of the most annoying thing when working with terraform is the size of output of the terraform plan command. For more complex environments, it easily can get to many thousand lines, even for what seems to be a small change. It makes very hard to confirm that a code change does not have a side effects. </p><p>It would be nice to have the summary option, showing only resources and modules changed. I guess one day such feature will be added. In the meantime, I thought to use the grep command on the terraform plan output. It wasn't easy, because the output contain a few control character. After quite a few attempts, I found that following regex is a substitute. <br /></p><pre>terraform plan | grep -E "^[[:cntrl:]][[:print:]]+[[:space:]]+#\ "
</pre><br />Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-2120619908588484882023-05-17T20:35:00.006+01:002023-11-10T07:47:12.782+00:00How to find s3 bucket in multiple accounts (with awk and multiple field separator)
<p>Imagine you have quite a few AWS accounts. In one of them, you don't know which one, there is an S3 bucket. The AWS CLI with awk and zsh can help to find it.</p><p>In the first step, let's prepare a list of all accounts, or rather profiles from the AWS CLI config (the ~/.aws/config file).<br /></p><pre><code>accounts=($(awk -F "( |])" '/profile sso/ {print $2}' ~/.aws/config))
</code></pre>
<p> In the example, we limit the list only to profiles with the prefix "sso". The command uses awk to find any line with the string "profile sso" and print the second field from it. However, it does no use the standard field separator. There are 3 characters working as a separator: space, "|" and "]". Please also note the awk command is two pairs of "()".<br /></p><p> The list is saved into the accounts variable and used in the second command. It lists all s3 buckets from each account, and grep for the selected string, which of course can be the whole bucket name.<br /></p><pre><code>p=sso-prod </code></pre><pre><code>bucket=my-company-not-so-important-bucket</code></pre><pre><code>for accounts ($accounts) {echo $account; aws s3 ls --profile $p| grep $bucket}
</code></pre>
Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-60934121257665436092022-08-30T09:43:00.002+01:002022-08-30T09:43:11.809+01:00Network debugging in k8s<p> </p><p> Sometimes it is good to look at a network from the inside of a kubernetes cluster. Well-prepared images do not have any useful networking tools (because they are minimal image designed to do specific task). Therefore, you might need to run commands from a dedicated container. An example of such tool is the <i>netshoot</i> image. It can be found in GitHub: <a href="https://github.com/nicolaka/netshoot">https://github.com/nicolaka/netshoot</a></p><p>It's very easy to run: <br /> </p><p> <code>
kubectl run tmp-shell --rm -i --tty --image nicolaka/netshoot
</code>
</p><p><br /></p>Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-1477992466821475962022-05-31T15:57:00.005+01:002022-05-31T15:57:36.434+01:00Jenkins and Splunk (Cloud)<p>There is the Jenkins Plugin to set log export to Splunk. In Splunk Marketplace you can find the <a href="https://splunkbase.splunk.com/app/3332/" target="_blank">Splunk App for Jenkins</a>, but the app works only for Splunk Enterprise, not the Cloud edition. Documentation describe how to connect Jenkins to Splunk. It includes values for cloud deployment as well as on-premises one. Thanks to that, the connection was easy to establish, but there were no logs from Jenkins. I had to manually created 4 indexes (I got them from <a href="https://community.splunk.com/t5/All-Apps-and-Add-ons/Jenkins-data-sourcetype-mapping/m-p/413295" target="_blank">this discussion</a>) to get Jenkins logs visible in Splunk.<br /></p>Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-38778384660973190232021-12-27T18:15:00.004+00:002022-01-05T07:59:09.417+00:00Sims 4 (and Origin client) on Linux with Steam<p>Recently, I've spent some time trying to make Sims 4 running on Linux. (That's the way you might spend time when you have a growing up daughter.) The<a href="https://www.protondb.com/app/1222670" target="_blank"> ProtonDB entry</a> was (and still is) GOLD, so it was encouraging. However, it didn't work on the first computer I tried. Steam client showed the game ran, but there was no window. Neither for the Sims 4 game, nor for the Origin client. It was:</p><ul dir="auto"><li>Distro: Mint 20.2<br /></li><li>CPU: Intel i5-7400</li><li>GPU: Nvidia (Zotec GT 610 1GB)</li><li>Kernel: 5.4.0-88 (Ubuntu/Mint)</li><li>Drivers: Nvidia closed source 390.144</li><li>Mesa: 21.0.3</li><li>Proton: various versions</li><li>Sims 4 works: No<br /></li></ul><p dir="auto">Then I tried on my Crux machine, and it worked fine. I don't remember if I had to add PROTON_USE_WINED3D=1. The machine had:</p>
<ul dir="auto"><li>Distro: CRUX 3.6.1 <br /></li><li>CPU: AMD Ryzen 5 2400G</li><li>GPU: AMD RX 6600 XT</li><li>Kernel: 5.13.2</li><li>Drivers: amdgpu</li><li>Mesa: 21.2.2</li><li>Proton: 6.3.7</li><li>Sims 4 works: Yes <br /></li></ul><p>So I thought that maybe GPU from the original machine was too old, or NVidia drivers were causing problems. I replace the Nvidia GPU <span>an AMD FirePro V5900 card. It didn't help. <br /></span></p><p><span>The next step was to run a test on my old Dell XPS-13 laptop. I installed the OpenSuse Leap 15.3 on it. I played a bit with Proton version, but in the end Sims started with the Proton </span>7.0rc2-GE-1, the latest release <span>from the <a href="Glorious Eggroll" target="_blank">Glorious Eggroll</a> branch.</span></p><ul dir="auto"><li>Distro: OpenSuse Leap 15.3 <br /></li><li>CPU: Intel i7-4510<br /></li><li>GPU:Intel i915<br /></li><li>Kernel: 5.13.18-59.10-default</li><li>Drivers: intel</li><li>Mesa: 20.2.4</li><li>Proton: 7.0rc2-GE-1</li><li>Sims 4 works: Yes <br /></li></ul><p><span></span></p><p>In the same time, I realized that I could swap CPUs between machines. The Ryzen had the build in Vega GPU core, which was not in use. The first phase was to check that Sims 4 could start on CRUX without discrete GPU. It worked fine. Then I swapped the CPUs (with motherboards). The CRUX (with Intel CPU and AMD GPU) worked fine, but the Mint with AMD Ryzen (and integrated AMD GPU) still struggled. I tried using the Proton from GE branch, which helped me on OpenSuse. No luck.</p><ul dir="auto"><li>Distro: Mint 20.2<br /></li><li>CPU: AMD Ryzen 5 2400G</li><li>GPU: AMD Radeon Vega 11</li><li>Kernel: 5.15.6-1-default<br /></li><li>Drivers: amdgpu</li><li>Mesa:21.3.1</li><li>Proton: 6.3.8</li><li>Sims 4 works: No</li></ul><p>I started to consider that something wrong is with Mint. The Sims 4 problem seems to be the problem with Origin client. The first relatively easy change was to use the KDE instead of Cinnamon as a Window Manager for the Mint system. It didn't help. Next was to install OpenSuse along Mint. The only change compared to the Dell laptop was to use the Tumbleweed rather than the Leap edition.</p><ul dir="auto"><li>Distro: OpenSuse Tumbleweed <br /></li><li>CPU: AMD Ryzen 5 2400G</li><li>GPU: AMD Radeon Vega 11</li><li>Kernel: 5.15.6-1-default<br /></li><li>Drivers: amdgpu</li><li>Mesa:21.3.1</li><li>Proton: 6.3.8</li><li>Sims 4 works: Yes <br /></li></ul><p>This time it worked fine. No issues. In conclusion, there is something wrong with Mint, but Sims 4 and Origin client works fine on Linux with Steam.<br /></p>Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-8451666672509862372021-11-04T08:17:00.007+00:002021-11-04T08:17:54.303+00:00dmidecode - the command I always forget about<p> </p><p>From time to time I need to check some details of the hardware in one of my Linux server. There is a good command to do this, which I know exists and have good functionality, but cannot remember the actual text to call it. The command in question is:</p><p style="text-align: center;"><b>dmidecode</b><br /></p><p>And below links with examples and explanation how to use it: <br /></p><ul style="text-align: left;"><li> https://www.ubuntupit.com/simple-and-useful-dmidecode-commands-for-linux/</li><li> https://linuxiac.com/dmidecode-get-system-hardware-information-on-linux/</li></ul>Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-63418000727203936822021-07-20T12:54:00.000+01:002021-07-20T12:54:05.203+01:00How to check Jenkins credentails<p>If you every need to check what are the actual password in Jenkins credentials check this <a href="https://gist.github.com/timja/04afb12c8ad909e400317a2ad9c88445" target="_blank">small groovy script</a> by <a href="https://gist.github.com/timja" target="_blank"><span class="p-name vcard-fullname d-block overflow-hidden" itemprop="name">Tim Jacomb</span></a><span class="p-name vcard-fullname d-block overflow-hidden" itemprop="name">. I helped me to confirm that credentials were corrupted during saving and restoring with Configuration as a Code plugin.<br /></span></p><p><span class="p-name vcard-fullname d-block overflow-hidden" itemprop="name">To use it (and any other groovy script). In your Jenkins:</span></p><ul style="text-align: left;"><li><span class="p-name vcard-fullname d-block overflow-hidden" itemprop="name">go to the <b></b></span><b>Manage Jenkins</b> page, </li><li>find the <b>Script Console</b> link in the <b>Tools and Actions</b> section, </li><li>copy and paste the script into the text field </li><li>run it<br /></li></ul><p><span class="p-name vcard-fullname d-block overflow-hidden" itemprop="name"></span></p>Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-70936908153988039922021-05-01T20:19:00.006+01:002021-05-01T20:19:53.772+01:00ABCDE in Crux<p>After my OS update to Crux 3.6 (3.6.1 to be precise) I cleaned non-main (core, opt, xorg) packages. One of the side effects is that I lost <i>abcde</i>. It was removed from the contrib collection, because of inactive maintainer. Along <i>abcde</i>, the <i>cd-discid</i> was also deleted from the same reason. I decided to add them to my port collections (<a href="https://wawrzek.name/crux/repo/">https://wawrzek.name/crux/repo/</a>). I started from the old contrib ports. Looking at sources I noticed that there is a recent patch for cd-discid. I included it into my port. I also encounter problems in running abcde with my config. There were missing musicbrainz Perl modules, so I added ports for them as well.<br /></p>Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-24838330719050926762021-03-01T21:41:00.000+00:002021-03-01T21:41:02.473+00:00Pulse and default sound card<p>For some reason <a href="https://en.wikipedia.org/wiki/PulseAudio">PulseAudio</a> wants to send sounds from my computer to the HDMI monitor, with rather crappy speakers, rather than to my headphones. <br /></p><p>To stop it I set up a default output by editing <b>/etc/pulse/default.pa</b>. In my case the right configuration was:<br />
</p><pre>set-default-sink alsa_output.pci-0000_38_00.6.analog-stereo</pre>Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-79004581216063722072020-11-28T15:02:00.002+00:002020-11-28T15:02:41.408+00:00Enforce module load in CRUX<p>At the moment, my Linux (<a href="http://crux.nu" target="_blank">CRUX</a> 3.5) does not load a kernel module for the my mainboard monitoring chipset. The mainboard is GigaByte GA-M68MT-S2 and the chip is Nuvoton NCT6775F. I need data from that chip for Conky or LM Sensors. To ensure it's available I've modified the <i><b>/etc/rc.modules</b></i> file, by adding</p>
<pre>modprobe nct6775</pre>
Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-67418011717607485572020-11-20T14:17:00.004+00:002020-11-20T14:17:41.733+00:00Debugging of Ansible and MoleculeAs I descrbided in <a href="https://larryn.blogspot.com/2020/08/molecule-and-extra-variables-for-ansible.html">this article</a> additional Ansible options are passed at the end of molecule command. This can be use to increase verbosity of Ansible:
<pre>
molecule converge -- -vvvv
</pre>
Molecule own debug information can be printed to the standard output with *--debug** option, but it has be specify without molecule command. For example:
<pre>
molecule --debug converge
</pre>
Of course, both can be mixed togther:
<pre>
molecule --debug converge -- -vvvv
</pre>Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-69261999728751864752020-11-01T18:30:00.003+00:002020-11-01T22:17:44.647+00:00edsn: Elite Dangerous Star Neighborhood<h3 style="text-align: left;"> Description<br /></h3>
<p style="text-align: left;">Virtual, for ever I was fascinating with maps of our star neighbourhood. Just like the one from <a href=" https://www.eso.org/public/images/eso0303c/" target="_blank">European Southern Observatory</a> website. Recently, I've enjoyed playing <a href="https://elite-dangerous.fandom.com/wiki/Elite_Dangerous_Wiki" target="_blank">Elite Dangerous</a>. I enjoy it even more, because it works perfectly fine on Linux (with <a href="Phttps://www.protondb.com/app/359320" target="_blank">Proton</a>). One of the great thing about Elite is freedom to roam between stars and visit, so many star neighbourhoods. </p><p style="text-align: left;">The amount of stars is breathtaking. It's hard to visualize the ones which are close to the system you are in. So, I wrote a small Python script to get data from <a href="ehttps://www.edsm.net/" target="_blank">edsm</a> and prepare them to be visualized with <a href="http://gnuplot.sourceforge.net/" target="_blank">GNUplot</a>.</p>
<h3 style="text-align: left;">Examples</h3>
<h4 style="text-align: left;">Sol</h4>
<p style="text-align: left;">Home, sweet home.</p>
<p><a href="http://wawrzek.name/elite/sol-r15.png"><img alt="Stars in less than 15 Light Years from Sol" src="http://wawrzek.name/elite/sol-r15.png" width="600" /></a></p>
<p>These are the commands to produce the SVG output after loading script and data into Gnuplot. <br /></p>
<pre style="text-align: left;">set term svg size 1600,1200
set view 45, 290, 1.25, 1.5
set output 'sol-r15.svg'; replot
</pre>
<h4 style="text-align: left;">Achenar</h4>
<p style="text-align: left;"> I didn't know that the space around Achenar is so empty (OK. I don't have permit yet). <br /></p>
<p><a href="http://wawrzek.name/elite/achenar-r15.png""><img alt="Stars in less than 15 Light Years from Achenar" src="http://wawrzek.name/elite/achenar-r15.png" width="600" /></a></p>
<p>These are the commands to produce the SVG output after loading script and data into Gnuplot. <br /></p>
<pre style="text-align: left;">set term svg size 1600,1200
set view 45, 275, 1.25, 1.5
set output 'achenar-r15.svg'; replot
</pre><p></p>Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-40176111587485133242020-10-22T21:36:00.006+01:002020-11-28T15:04:08.208+00:00Kernel module info<p>A few commands to help in checking and adjusting kernel module options: </p><ol style="text-align: left;"><li>Display information about kernel module, including all options <br /><br /><span style="font-family: courier;"><b>modinfo $KERNEL_MODULE</b></span><br /><br /></li><li>Display information about current value for each option<br /><br /><span style="font-family: courier;"><b>for i (/sys/module/$KERNEL_MODULE/parameters/*) {\<br /> echo $(basename $i);\<br /> cat $i\<br />}</b></span><br /><br /></li><li>Change kernel module option without restart (temporary)<br /><br /><span style="font-family: courier;"><b>echo "$NEW_VALUE" > /sys/module/$KERNEL_MODULE/parameters/$OPTION</b></span><br /><br /></li><li>Load module with an option set to value<br /><span class="crayon-e"></span><b><span style="font-family: courier;"><span class="crayon-i">insmod</span><span class="crayon-h"> </span>$PATH_TO_MODULE/$KERNEL_MODULE.ko\<span class="crayon-e"> $OPTION</span></span><span class="crayon-o"><span style="font-family: courier;">1=$VALUE1 \<br />$OPTION2=$VALUE2</span><br /><br /> </span></b><span class="crayon-cn"></span><span class="crayon-h"> </span><span class="crayon-cn"></span></li><li>Ensure kernel module option is set during boot up with grub</li><ol><li>Open <b>/etc/default/grub</b></li><li>Add/edit following line<br /><span style="font-family: courier;"><b>GRUB_CMDLINE_LINUX='$KERNEL_MODULE.$OPTION=$VALUE'</b></span><br /></li></ol></ol><p>Of course $KERNEL_MODULE, as well as all other strings with "$" at the beginning, has to be replaced by appropriate value.</p><p>In CRUX /etc/default/grub does not exist, so it has to be created.<br /></p><p><b> Useful links</b></p><ul style="text-align: left;"><li><a href="https://www.cyberciti.biz/tips/how-to-display-or-show-information-about-a-linux-kernel-module-or-drivers.html">https://www.cyberciti.biz/tips/how-to-display-or-show-information-about-a-linux-kernel-module-or-drivers.html</a></li><li><a href="https://devarea.com/linux-kernel-development-kernel-module-parameters/">https://devarea.com/linux-kernel-development-kernel-module-parameters/</a></li><li><a href="https://www.howtoforge.com/tutorial/kernel-boot-parameter-edit/">https://www.howtoforge.com/tutorial/kernel-boot-parameter-edit/</a></li><li><a href="https://www.linuxsecrets.com/1455-adding-kernel-boot-parameters-using-grub-on-linux">https://www.linuxsecrets.com/1455-adding-kernel-boot-parameters-using-grub-on-linux</a><br /></li></ul>Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-66981050615575132432020-10-11T18:37:00.000+01:002020-10-11T18:37:08.077+01:00Shell script to setup system with new kernel<p> </p><p>This is a small script helping in setting up a new kernel. It copies files from the Linux kernel source directory and builds the matching initramfs file.<br /></p><p> </p>
<pre>#!/bin/sh
#
set -x
if [ $(dirname $PWD) != '/usr/src' ]
then
echo ""
echo "Please change directory to a one with Linux kernel sources"
exit 1
fi
version=$(basename $PWD |awk -F\- '{print $2}')
ls boot/vmlinuz-${version}-* 2> /dev/null && \
build=$(ls -1 /boot/vmlinuz-${version}-*| sort -n | awk -F\- '{print $3}') || \
build=1
release=${version}-${build}
cp System.map /boot/System.map-${release}
cp arch/x86/boot/bzImage /boot/vmlinuz-${release}
mkinitrd /boot/initramfs-${release}.img ${version}
grub-mkconfig > /boot/grub/grub.cfg
</pre>Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-4974632021059987312020-08-28T13:46:00.001+01:002020-08-28T13:46:16.795+01:00Molecule and extra variables for Ansible<p>Imagine that you want to use Molecule to test an Ansible role with a not default value. That's just one off test, so adjusting molecule configuration in the converge.yml (or similar) file is not required. It's not very prominent in <a href="https://molecule.readthedocs.io/en/latest/usage.html#converge" target="_blank">documentation</a>, but you can pass Ansible variables after "--" (minus, minus) in the molecule commend. For example:</p>
<pre>molecule converge -- -e "role_new_var=true"</pre>Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-92154121073430032582020-08-26T14:08:00.003+01:002020-08-26T14:08:31.781+01:00How to find a word in files spread over many subdirectories<p>Imagine that you need to try to find a word in hundreds files located in a plenty of subfolders. <i>grep -Rc</i> might be a good candidate, but it's going to print the list of all files and the word is in just a handful of them. To make the output better <i>grep</i> can be joined with <i>awk</i> (and in the example below with <i>zsh</i>). </p><p>I needed to find an example of sqlcmd command usage in my Ansible roles collection. I used the power of ZSH globbing (a few other examples can be found <a href="https://www.techrepublic.com/article/globbing-wildcard-characters-with-zsh/">here</a> and in other places) to limit search to yml file only. ZSH "<b>**</b>" pattern is also a nice replacement to the <i>grep</i> "<b>--recursive</b>"option. In <i>awk </i>the<i> </i>"<b>-F</b>" flag<i> </i>replaces the standard delimiter with the "<b>:</b>" character and prints only lines with second field not equal to zero.<br /></p><pre>grep -c sqlcmd **/*.yml | awk -F":" ' ($2 != 0 ){print $0}'</pre>Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-65671234704249388442020-04-29T16:50:00.000+01:002020-04-29T16:50:06.477+01:00 Get Public IP address of Azure VM from shell on VM - part IILast year I wrote a <a href="https://larryn.blogspot.com/2019/04/get-public-ip-address-of-azure-vm-from.html">quick note</a> with a method of getting Azure VM public address from the shell on VM. Recently I spent a bit more time to look at <a href="https://docs.microsoft.com/en-us/azure/virtual-machines/linux/instance-metadata-service">https://docs.microsoft.com/en-us/azure/virtual-machines/linux/instance-metadata-service</a> and found more precise call to get IP address from the metadata url: <br />
<br />
<pre>curl -H Metadata:true \
"http://169.254.169.254/metadata/instance/network/interface/0/ipv4/ipAddress/0/publicIpAddress?api-version=2017-08-01&format=text"</pre><br />
BTW. The same method allows to get a private IP address.<br />
<br />
<pre>curl -H Metadata:true \
"http://169.254.169.254/metadata/instance/network/interface/0/ipv4/ipAddress/0/privateIpAddress?api-version=2017-08-01&format=text"</pre>Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-84039227846863839292020-04-07T15:11:00.000+01:002020-04-07T15:27:56.159+01:00Painful encounter with oversized Postgres (9.6)I had not so nice encounter with an oversize PostgresDB. Somehow rather small DB ballooned to 256 GB (what was a partition size). I'm not PostgresDB expert. I can barely use it, but I've spent some time doing internet search and that might be useful for other (or for me in the future).<br />
<br />
In the end I regained nearly 200 GB of space with simple command:<br />
<br />
<pre>vacuum full</pre>
<br />
As it is suggested by this <a href="https://stackoverflow.com/questions/28032850/how-to-shrink-pg-toast-table#28039514"> Stack Overflow question</a>.<br />
<br />
The key to find above suggestion was to understand that the problem was related to pg_toast table. I found that fact out using oid2name tool, which BTW in Ubuntu is in /usr/lib/postgresql/10/bin/. <br />
<br />
<br />
<pre>/usr/lib/postgresql/10/bin/oid2name -H localhost -U postgres -d postgres -f 24806
From database "postgres":
Filenode Table Name
--------------------------
24806 pg_toast_24729
</pre>
<br />
<br />
I learnt about the tool from this <a href="https://www.postgresql.fastware.com/blog/where-and-how-is-your-data-actually-stored-on-disk">document</a> and learnt how to use from the <a href="https://helpmanual.io/man1/oid2name/">man page</a>.<br />
<br />
It's also worth to remember that following query didn't help me. I think it's nice, so posting it here, anyway:<br />
<br />
<pre>SELECT table_schema,
table_name,
pg_relation_filepath('"'||table_schema||'"."'||table_name||'"')
FROM information_schema.tables
WHERE
pg_relation_filepath('"'||table_schema||'"."'||table_name||'"')
LIKE 'base/12404/248%';
</pre>
<br />
The above query was built based on another good suggestion from <a href="https://stackoverflow.com/questions/21738408/postgresql-list-and-order-tables-by-size#21738505">Stack Overflow</a>. This one shows all big tables.<br />
<br />
<pre>SELECT
table_schema,
table_name,
pg_relation_size('"'||table_schema||'"."'||table_name||'"')
FROM information_schema.tables
ORDER BY 3
LIMIT 10
</pre>
Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-86507733967799109102020-03-16T10:11:00.001+00:002020-03-16T10:12:11.805+00:00prt-get/pkgmk adjustmentsIf I'm ever going to lose my current Crux config. I need to remember, to adjust following files for Crux:<br />
<ul><li><b>/etc/prt-get.conf</b> to ensure that scripts as executed:<br />
<br />
<pre>runscripts yes # (no|yes)</pre><br />
<br />
</li>
<li><b>/etc/pkgmk.conf</b> to ensure that md5sums are ignored:<br />
<br />
<pre>PKGMK_IGNORE_MD5SUM="yes"</pre><br />
</li>
</ul>Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-27526814083680290902020-03-12T10:33:00.001+00:002020-03-12T10:53:24.213+00:00Bash and ArraysShort reminder for my 'extended memory' on how to deal with lists in bash.<br />
<br />
To define:<br />
<ul><li>a list (an array): <b>declare -a list</b></li>
<li>a dictionary (an associative array): <b>declare -A dict</b></li>
</ul>To use an array in loop: <b>for item in ${list[@]}</b> <br />
<br />
Now the best, at least for scripts testing:<br />
To print a whole array: <b>declare -p list</b> (please note, no "$" before list name).<br />
<br />
<br />
<i>Found at <a href="https://www.tutorialkart.com/bash-shell-scripting/bash-array/">https://www.tutorialkart.com/bash-shell-scripting/bash-array/</a></i><br />
<br />
<br />
Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-70740034109970968992019-11-30T13:21:00.001+00:002020-10-11T18:51:19.545+01:00AMDGPU firmware and homebuild kernelNot sure how it happens in less DIY type distributions, but in Crux I struggled to add firmware of AMDGPU drivers to a initrmfs. Maybe I haven't tried long enough, but without firmware in the initial ramfs, I could not properly start my desktop.<br />
<br />
I learnt that drivers are on a disk, in what looked like the right directory (<b>/lib/firmware/amdgpu/</b>). They just were not loaded. After passing a few times the directory name via a CLI option I figured out that the path could be added to the dracut config.<br />
<br />
Now, I have following config file on which make rebuilding kernel much easier.<br />
<br />
<pre>cat /etc/dracut.conf.d/wawrzek.conf
install_items+=/lib/firmware/amdgpu/*
</pre><br />
Thanks to that I can simple run command like that to add ramfs to:<br />
<br />
<pre>mkinitrd /boot/initramfs-5.4.0-1.img 5.4.0
</pre>Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-4482182819845824482019-09-06T15:57:00.002+01:002019-09-06T16:04:17.459+01:00Copy files around in CentOS with SELinux (e.g. Nginx)Imagine that you want to enable https traffic on a site served by Nginx. Sounds simple. A series of command like these should work:<br />
<br />
<pre>scp example.com.* your_remote_server:
ssh your_remote_server
sudo mkdir /etc/nginx/ssl
sudo cp example.com.* /etc/nginx/ssl
</pre>
<br />
Edit appropriate configuration file(s). Finally, run:<br />
<br />
<pre>sudo systemctl restart nginx
</pre>
<br />
and nothing, or rather an error message with information that nginx cannot access ssl certificate files. You check and files exists, so what's the problem?<br />
<br />
The problem is a SELinux security context, diffrent for /etc/ngnix and /home/X<br />
<br />
To change it you need to run <b>chcon</b>. For example:<br />
<br />
<pre>chcon --reference /etc/nginx/nginx.conf /etc/nginx/ssl/example.com.*</pre>
<br />
More info at: <a href="https://www.cyberciti.biz/faq/rhel-centos-feora-linux-change-copy-selinux-context/">https://www.cyberciti.biz/faq/rhel-centos-feora-linux-change-copy-selinux-context/</a>Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0tag:blogger.com,1999:blog-19023061.post-34036859735427107712019-07-03T11:59:00.003+01:002019-07-03T11:59:57.598+01:00OpenSSL and certsI was battling with SSL certificates recently and have two useful command I would like to store in my extended memory (this blog).<br />
<br />
<br />
a) To ensure that all certificates in a bundle are OK. There should be a clear 'line of trust' in output.<br />
<br />
<div class="container" title="Hint: double-click to select code">
<div class="line number1 index0 alt2">
<code class="java plain">FILENAME=your.domain.crt</code><br />
<code class="java plain">openssl crl2pkcs7 -nocrl -certfile $FILENAME | openssl pkcs7 -print_certs -noout</code></div>
<div class="line number2 index1 alt1">
<br />
b) To ensure that the EC (Eliptic Curve) key in the csr and the certifciate is equal to the actual signing key run these 3 commands. The public key for each command should be the same.<br />
<br />
<code class="java plain">NAME=your.domain</code></div>
<div class="line number2 index1 alt1">
<code class="java plain">openssl ec -pubout -in $NAME.key</code></div>
<div class="line number3 index2 alt2">
<code class="java plain">openssl req -noout -pubkey -in $NAME.csr</code></div>
<div class="line number4 index3 alt1">
<code class="java plain">openssl x509 -noout -pubkey -in $NAME.crt</code></div>
</div>
Wawrzekhttp://www.blogger.com/profile/12537908697081902130noreply@blogger.com0