TL;DR
There is a non-standard -r option to xargs that allows it to skip executing when there are no arguments at all.
On some operating systems, the -r is default.
MacOS has no -r, but does not execute xargs if there are no arguments given.
Posted by jpluimers on 2021/07/28
There is a non-standard -r option to xargs that allows it to skip executing when there are no arguments at all.
On some operating systems, the -r is default.
MacOS has no -r, but does not execute xargs if there are no arguments given.
Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, Software Development, xargs | Leave a Comment »
Posted by jpluimers on 2021/07/27
This is a continuation of yesterdays
Listing information on all active interfaces on MacOS part 1: getting the active interface names.
It is based on ideas in these StackExchange posts:
I threw most of the implementation details in the ideas away, as they were way to much based on empirical trial and error, than proper research.
So I tried doing the research and came up with the things below.
By using the ipconfig command, you can get specific details for a NIC like an IPv4 (with the getifaddr) or DHCP (with the getpacket option to get the latest DHCP packet):
for i in $(ifconfig -l -u); do if ifconfig $i | grep -q "status: active" ; then echo $i; fi; done | xargs -n1 -I_nic_ sh -c 'echo "_nic_: $(ipconfig getifaddr _nic_)"'
or DHCP/BOOTP:
for i in $(ifconfig -l -u); do if ifconfig $i | grep -q "status: active" ; then echo $i; fi; done | xargs -n1 -I_nic_ sh -c 'echo "_nic_: $(ipconfig getpacket _nic_)"'
The latter returns a very long list, which I wanted to shorten into a more readable format.
You can find more information in the [Archive.is] ipconfig(8) [osx man page] / [WayBack] ipconfig Man Page – macOS – SS64.com excerpt:
Posted in *nix, *nix-tools, Apple, bash, Development, DNS, ifconfig, Mac OS X / OS X / MacOS, Power User, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2021/07/22
A few years back, Ken Thompson’s 1980 Unix password got cracked.
It took that long because his password p/q2-q4! had enough entropy by using uncommon characters so the crypt(3) based hash ZghOT0eRm4U9s was hard to crack.
The password was an opening chess move noted in the variety of the descriptive notation. A shorter notation would have been P-Q4, which would require months to crack in that era.
In modern chess notation, it would be 1. d4, moving the Queen’s Pawn from d2 to d4.
References (many interesting messages in the TUHS thread below):
Posted in *nix, B, C, Development, Power User, Security, Software Development | Leave a Comment »
Posted by jpluimers on 2021/07/21
On one of my Raspberry Pi boxes, somehow I could not access files over SFTP (SSH File Transfer Protocol) via FileZilla.
I would consistently get this error:
"Connection timed out after 20 seconds of inactivity"
Figuring the exact cause took a while.
TL;DR: SFTP uses an interactive non-login shell, then interprets the output from that shell. For that kind of shell, ensure few or none scripts run that output text.
Posted in *nix, *nix-tools, bash, bash, Communications Development, Conference Topics, Conferences, Development, Event, Internet protocol suite, Power User, Scripting, SFTP, Software Development, SSH, TCP | Leave a Comment »
Posted by jpluimers on 2021/07/19
[WayBack] windows – Is there any sed like utility for cmd.exe? – Stack Overflow
TL;DR: many people suggest to use PowerShell, but there is GNU sed in Chocolatey
The chocolatey part:
Instructions for building [WayBack] Gnu Sed as a native windows application
All patches under the same license as sources of [WayBack] Gnu Sed: [WayBack] GPLv3 or later
sed.exe was exactly the binary [WayBack] sed-windows/sed-4.5-x64.exe at cafe68124fb8f01db3fb1d9ea586f8f6a72d6917 · mbuilov/sed-windows · GitHubThe PowerShell part: read the other answers from the above question.
–jeroen
Posted in *nix, *nix-tools, CommandLine, Power User, PowerShell, RegEx, sed, Windows | Leave a Comment »
Posted by jpluimers on 2021/07/09
Based on
This scans the 192.168.1.0/24 network for SMB capable machines, and extracts information from them:
nmap -p139,445 --script smb-os-discovery 192.168.1.0/24
Note that experimenting this, I found out that nmap is also available on Chocolatey: [WayBack] Chocolatey Gallery | Nmap 7.70 (heck, since 2016, no less!).
I was hoping I wrote a little batch file around this, called find-smb-hosts.on.192.168.1.network.bat, because net view is working not so well on Windows 10 any more, but that failed, so here is the batch file:
@echo off :: only works from older versions than Windows 10 :: the delay is caused by the "net view" scanning the network :: the first for calls ping with the hostname :: the second for gets the IP and hostname without waiting for a ping result for /f "usebackq tokens=1* delims=\ " %%m in (`net view ^| findstr "\\"`) do ( for /f "usebackq tokens=2,3 delims=[] " %%h in (`ping -4 %%m -n 1 -w 1 ^| grep Pinging`) do ( echo %%i %%h ) ) goto :eof :: output of the first for without filtering (no starting newline): :: Server Name Remark :: :: ------------------------------------------------------------------------------- :: \\REVUE Samba 4.7.3-git.30.54c196e5d35SUSE-oS15.5-x86_64 :: \\VCS-CI :: The command completed successfully. :: output of the second for without filtering (including the starting newline): :: :: Pinging revue [192.168.1.62] with 32 bytes of data: :: Reply from 192.168.1.62: bytes=32 time<1ms TTL=64 :: :: Ping statistics for 192.168.1.62: :: Packets: Sent = 1, Received = 1, Lost = 0 (0% loss), :: Approximate round trip times in milli-seconds: :: Minimum = 0ms, Maximum = 0ms, Average = 0ms
The above batch file delivered many more results than this line:
nmap -p139,445 --script smb-os-discovery 192.168.71.1/24 | grep -w "\(report\|Computer name\)"
–jeroen
Posted in *nix, *nix-tools, nmap, Power User | Leave a Comment »
Posted by jpluimers on 2021/06/28
From [WayBack] How to rename a VM through SSH on ESXi ? |VMware Communities (numbering and code highlighting mine):
Kindly find the below:
- Backup the virtual machine
- Power down the virtual machine
- Remove the virtual machine from the vSphere host inventory
- Open an SSH console session to the vSphere host
- Navigate to the storage directory containing the virtual machine: For example:
cd /vmfs/volumes/<datastore_name>/<original_vmname>- Rename the primary
.vmdkconfiguration files:vmkfstools -E "<original_vmname>.vmdk" "<new_vmname>.vmdk"- Rename the
.vmxconfiguration file:mv "original_vmname.vmx" "new_vmname.vmx"- Edit the virtual machine .vmx configuration file (Be sure to properly update the directory and file name of the
.vswpswap file reference):vi "new_vmname.vmx"- Rename any remaining files in the virtual machine’s folder as needed:
- Rename the
.vmxfconfiguration file:mv "original_vmname.vmxf" "new_vmname.vmxf"- Rename the
.nvramconfiguration file:mv "original_vmname.nvram" "new_vmname.nvram"- Rename the
.vsdconfiguration file:mv "original_vmname.vsd" "new_vmname.vmsd"- Rename the virtual machine folder: Move up one directory level to the parent folder (
cd ..) then rename the virtual machine directory:mv "original_directory" "new_directory"- Add the newly-named virtual machine to the host’s inventory (the newly renamed
.vmxconfiguration file)- Power on the newly renamed virtual machine
- Answer “I moved it” to the virtual machine question prompt (not “I copied it”)
- Review the virtual machine and all files/folders to make sure it is named as desired and functioning properly
Note: There are other methods to allow for renaming, but this method is fairly quick and easy. It should work on all editions of vSphere from free to Enterprise Plus.
The “Answer question” prompt where you should selected “I moved it”:
->
On a site note, I need to figure uit how to set the ESXi shell prompt to show the current path like pwd does (with symlink names in it instead of the followed symlink targets):
[root@ESXi-X9SRI-3F:~] cd /vmfs/volumes/EVO860_250GB/ [root@ESXi-X9SRI-3F:/vmfs/volumes/5c9bd516-ef1f6d4c-f1b1-0025907d9d5c] pwd /vmfs/volumes/EVO860_250GB
The ESXi shell is based on busybox, in fact it uses the ash variety:
[root@ESXi-X9SRI-3F:/vmfs/volumes/5c9bd516-ef1f6d4c-f1b1-0025907d9d5c] `readlink -f \`which readlink\`` | grep ^BusyBox BusyBox v1.29.3 (2018-11-02 15:37:50 PDT) multi-call binary. BusyBox is copyrighted by many authors between 1998-2015. [root@ESXi-X9SRI-3F:/vmfs/volumes/5c9bd516-ef1f6d4c-f1b1-0025907d9d5c] type chdir chdir is a shell builtin
This seemed to work fine:
[root@ESXi-X9SRI-3F:/vmfs/volumes/5c9bd516-ef1f6d4c-f1b1-0025907d9d5c] PS1="[\u@\h:`pwd`] " [root@ESXi-X9SRI-3F:/vmfs/volumes/EVO860_250GB]
But in faxt fails, as it only takes a pwd value once, and not every time the prompt is evaluated:
[root@ESXi-X9SRI-3F:/vmfs/volumes/EVO860_250GB] cd .. [root@ESXi-X9SRI-3F:/vmfs/volumes/EVO860_250GB] pwd /vmfs/volumes [root@ESXi-X9SRI-3F:/vmfs/volumes/EVO860_250GB]
So I need to re-visit these links:
BusyBox has two shells, ash and hush. To see which one you have, run
type chdir: ash has it as a builtin (synonymous withcd), hush doesn’t. Both have an optional prompt expansion feature. Ash’s is enabled by activating theASH_EXPAND_PRMTfeature at compile time, while hush requiresFEATURE_EDITING_FANCY_PROMPT.When that feature is present, in ash the value of
PS1is expanded like a double-quoted string:$foo,$(command)and`command`constructs are expanded.Some backslash escapes are processed (in ash, after substitutions). They are a subset of bash’s.
\!: line history count\a: bell\b: backspace\e,\E: escape\f: form feed\h: host name\n: newline\r: carriage return\t: tab\u: user name (only withFEATURE_GETUSERNAME_AND_HOMEDIR)\v: vertical tab\w: current directory, with~for the home directory (only withFEATURE_GETUSERNAME_AND_HOMEDIR)\W: current directory (unabbreviated)\xHHor\XHHwhere HH are two hexadecimal digits: a character given by its hex code\[…\]: the enclosed text doesn’t count for width calculation purposes(If you’re looking at the source code, this happens in
parse_and_put_promptinlibbb/lineedit.c.)
–jeroen
Posted in *nix, *nix-tools, BusyBox, ESXi6, ESXi6.5, ESXi6.7, Power User, Virtualization, VMware, VMware ESXi | Leave a Comment »
Posted by jpluimers on 2021/06/28
I hope that datendomina (@sys_adm_ama) has followed up with some cool vi/vim tips.
Though I can do basic editing (far more than quit-without-saving) and know about he various mode, I still feel not proficient.
[WayBack] Jeroen Pluimers on Twitter: “LOL! Boy was I glad that after finding my way in Ed and sed on SunOS in the 1980s, I discovered vi. Still not proficient in it (and I probably never will). However, knowing some of the basics allowed me to visually edit any file on any Unix like system. That’s still gold to me.…”
It also made me discover [WayBack] ed(1) Conference (@ed1conf) | Twitter.
One important tip:
[WayBack] Kristian Köhntopp on Twitter: “vi movement Kommandos haben System. Erkenne und lerne das System. hjkl + prefix+hjkl, Marken, prefix+jump to mark und so weiter. Und bleibe von den verblödeten Plugins weg. Die braucht kein Mensch und machen vim nur langsam im Start und kompliziert.”
The original thread, which I hoped would get longer: [WayBack] Thread by @sys_adm_ama: “Ich lerne jetzt vi(m). Klingt beknackt, oder?se […]”
Ich lerne jetzt vi(m).
Klingt beknackt, oder? Aber ich hab überlegt: ich möchte effizienter werden, meinen Kram stressfreier bewältigen. Und ich finde, es bietet sich an da an Baustellen anzusetzen, die täglich relevant sind. Und vi(m) nutze ich in der Tat täglich.
1/Aber auch wenn ich ihn nutze und über den »Hilfe, wie komm ich aus dem Editor wieder raus?!«-Witz nur sehr müde die Augen rolle gehe ich davon aus, dass ich nicht mal einen Bruchteil der Möglichkeiten ausschöpfe, die er bietet (1. Release 1976, älter als ich!). Das ist spannend.Das ist jetzt meine Mini-Challenge, auf die ich jeden Tag eine Viertelstunde verwenden will: wenn ich eine Funktion brauche mich nicht mehr drum herum zu hacken, sondern recherchieren wie es richtig geht und das dann gefälligst auch verinnerlichen. Mal sehen, ob das so klappt
3/In dem Zuge will ich auch wieder verstärkt (neo)mutt in Verbindung mit vim nutzen – das wäre ein wunderbares tägliches Training 😎 Mails schreiben muss man irgendwie immer.
neomutt bietet leider auch einen Eimer voll Funktionen, die ich noch nicht ordentlich nutze. Gnah.
4/An euren Replies erkenne ich, dass das mit dem »sich die Kürzel merken« echt heikel zu sein scheint 🤔 Wie handhabt ihr das im Alltag? Einfach ein paar Basics wie :u und CTRL+r und gut ist? Ich bin neugierig. Oder nutzt ihr alle nano? (Ich glaub, dann muss ich entfolgen) 😂Nur als kleinen Zwischenstand: nach dem Lesen eurer Antworten schließe ich, dass ich mich mit meinem Kenntnisstand nicht verstecken muss 😂 Da hat mir der virtuelle Schulterblick schon weiter geholfen.
/5vi(m), weil ich Admin bin und dieses Tool auf jedem System und ohne X-Geraffels üblicherweise vorfinde (wenn auch bei neueren Installationen dieser absurde „visual mode“ der Default ist 😳). Auch unter (Open)Solaris, IRIX, was weiß ich.
/6Eben hab ich das Buch von @MasteringVim aus der Packstation gezogen (extrem vielversprechend!) – und klar, ich werde berichten 😎 Ich bin sehr gespannt.
/7
ed
–jeroen
Posted in *nix, *nix-tools, Development, ed, Power User, Scripting, sed, sed script, Software Development, vi/vim | Leave a Comment »
Posted by jpluimers on 2021/06/07
Via [Archive.is] CloudKey ESXi Appliance – Google Search:
–jeroen
Posted in *nix, Cloud Key, ESXi6, ESXi6.5, ESXi6.7, Internet, Network-and-equipment, Power User, Unifi-Ubiquiti, Virtualization, VMware, VMware ESXi | Leave a Comment »