Archive for the ‘*nix’ Category
Posted by jpluimers on 2021/11/17
Even with lots of experience, one learns new things every day.
A while ago, I discovered checkbashisms which checks sh shel scripts (usually with extension .sh) scripts to they do not contain code specific to bash.
[Wayback] checkbashisms(1) – Linux man page
checkbashisms, based on one of the checks from the lintian system, performs basic checks on /bin/sh shell scripts for the possible presence of bashisms. It takes the names of the shell scripts on the command line, and outputs warnings if possible bashisms are detected.
Note that the definition of a bashism in this context roughly equates to “a shell feature that is not required to be supported by POSIX”; this means that some issues flagged may be permitted under optional sections of POSIX, such as XSI or User Portability.
In cases where POSIX and Debian Policy disagree, checkbashisms by default allows extensions permitted by Policy but may also provide options for stricter checking.
The source by now is a Perl script (it used to be a bash script) of which you can find the latest version here: [Wayback] scripts/checkbashisms.pl · master · Debian / devscripts · GitLab
Not installed by default
Virtually no distribution has checkbashisms installed by default.
In fact, the package containing checkbashisms heavily varies by distribution.
For OpenSuSE, it is in a package by itself: [Wayback] openSUSE Software: package checkbashisms
checkbashisms
Tool for Checking /bin/sh Scripts for Possible Bashisms
checkbashisms performs basic checks on /bin/sh shell scripts for the possible presence of bashisms. It takes the names of the shell scripts on the command line, and outputs warnings if possible bashisms are detected.
–jeroen
Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, sh, Sh Shell, Software Development | Leave a Comment »
Posted by jpluimers on 2021/11/17
[Wayback] How do I restart sshd on my Unix system | StarNet Knowledge Database – PC X, X Windows, X 11 & More – StarNet
RedHat and Fedora Core Linux
/sbin/service sshd restart
Suse linux
/etc/rc.d/sshd restart
Debian/Ubuntu
/etc/init.d/sshd restart
Solaris 9 and below
/etc/init.d/sshd stop
/etc/init.d/sshd start
Solaris 10
svcadm disable ssh
svcadm enable ssh
AIX
stopsrc -s sshd
startsrc -s sshd
HP-UX
/sbin/init.d/secsh stop
/sbin/init.d/secsh start
Note that for opensuse, by now you need this to restart sshd:
/usr/sbin/rcsshd restart
Edit 20211118: some tweets in reaction to this post
–jeroen
Posted in *nix, *nix-tools, Debian, Development, Linux, openSuSE, Power User, RedHat, Scripting, Software Development, SuSE Linux, systemd, Tumbleweed | Leave a Comment »
Posted by jpluimers on 2021/11/16
Never to old to learn new things: I was totally unaware of the GNU paste tool that is available on virtually all unix/Linux/BSD core installs.
Thanks [WayBack] zeppelin for answering this question at [WayBack] linux – Turning separate lines into a comma separated list with quoted entries – Unix & Linux Stack Exchange:
You can add quotes with sed and then merge lines with paste, like that:
sed 's/^\|$/"/g'|paste -sd, -
If you are running a GNU coreutils based system (i.e. Linux), you can omit the trailing '-'.
If you input data has DOS-style line endings (as @phk suggested), you can modify the command as follows:
sed 's/\r//;s/^\|$/"/g'|paste -sd, -
Now I can get a comma separated list of for instance ssh available mac algorithms:
# ssh -Q mac | paste -sd, -
hmac-sha1,hmac-sha1-96,hmac-sha2-256,hmac-sha2-512,hmac-md5,hmac-md5-96,umac-64@openssh.com,umac-128@openssh.com,hmac-sha1-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-md5-etm@openssh.com,hmac-md5-96-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com
Documentation:
–jeroen
Posted in *nix, *nix-tools, Development, Power User, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2021/11/09
Mid 2020, I re-installed a Raspberry Pi 2 box based on OpenSuSE Tumbleweed.
To my susprise the yast2 module sudo could not write the configuration.
It appeared that /etc/sudoers had become readonly and a new /etc/sudoers.d was created.
You can use visudo to edit files in that directory without potentially losing changes in /etc/sudoers during upgrades. I think that is a good move.
To bad the yast module failed because of it.
More on visudo and the /etc/sudoers.d directory:
–jeroen
Posted in *nix, Development, DevOps, Infrastructure, Linux, openSuSE, Power User, SuSE Linux, Tumbleweed | Leave a Comment »
Posted by jpluimers on 2021/11/03
I have the same problem mentioned in the answer to [WayBack] Terminating a script in PowerShell – Stack Overflow: confused by most answers, and keeping to forget what each method means (there is Exit, Return, Break and (if you love exception handling to do simple flow control), Throw.
So here is the full quote of what [WayBack] User New Guy answered:
Read the rest of this entry »
Posted in *nix, CommandLine, Development, Power User, PowerShell, PowerShell, Scripting, Software Development, Windows | Leave a Comment »
Posted by jpluimers on 2021/11/03
Some links for my archive; note that pure tar-pits by now are also hampering large email sender services like SendGrid, Mailgun and Amazon SES.
So the below links are for educational and historic purposes only.
I assembled these links because out of a sudden, Ring 2FA verification emails could not be delivered any more.
Ring 2FA came mandatory towards the end of February 2020.
Some links on that:
Sendmail timeouts:
–jeroen
Read the rest of this entry »
Posted in *nix, Communications Development, Development, HIS Host Integration Services, Internet protocol suite, Power User, SMTP | Leave a Comment »
Posted by jpluimers on 2021/10/28
After doing a lot of – historically grown – dash scripting for ESXi, I found out there is Python available on ESXi:
- Python 3.5.10 on VMware ESXi 6.7.0 build-17700523 (VMware ESXi 6.7.0 Update 3)
- Python 3.5.6 on VMware ESXi 6.5.0 build-13932383 (VMware ESXi 6.5.0 Update 3)
- VMware 7: to be determined.
Yes I know that Python 3.5 is end-of-life (and 3.5.10 was the latest version), but it is a lot better than shell scripts.
So now some links for my list of things to try in order to use Python for scripting ESXi operations:
–jeroen
Posted in *nix, *nix-tools, ash/dash, ash/dash development, Development, Power User, Python, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2021/10/27
Posted in *nix, *nix-tools, ash/dash, ash/dash development, bash, bash, Development, ESXi6, ESXi6.5, ESXi6.7, ESXi7, Power User, Scripting, Software Development, Virtualization, VMware, VMware ESXi | Leave a Comment »
Posted by jpluimers on 2021/10/26
This is sort of a follow-up on VMware ESXi console: viewing all VMs, suspending and waking them up: part 4 which already gave part of the configuration details of all the configured VMs.
Back then, we ended with this:
List the vmid values, power status and name of all VMs
Back to the listing script vim-cmd-list-all-VMs.sh:
#!/bin/sh
# https://wiert.me/2021/04/29/vmware-esxi-console-viewing-all-vms-suspending-and-waking-them-up-part-4/
vmids=`vim-cmd vmsvc/getallvms | sed -n -E -e "s/^([[:digit:]]+)\s+((\S.+\S)?)\s+(\[\S+\])\s+(.+\.vmx)\s+(\S+)\s+(vmx-[[:digit:]]+)\s*?((\S.+)?)$/\1/p"`
for vmid in ${vmids} ; do
powerState=`vim-cmd vmsvc/power.getstate ${vmid} | sed '1d'`
name=`vim-cmd vmsvc/get.config ${vmid} | sed -n -E -e '/\(vim.vm.ConfigInfo\) \{/,/files = \(vim.vm.FileInfo\) \{/ s/^ +name = "(.*)",.*?/\1/p'`
vmPathName=`vim-cmd vmsvc/get.config ${vmid} | sed -n -E -e '/files = \(vim.vm.FileInfo\) \{/,/tools = \(vim.vm.ToolsConfigInfo\) \{/ s/^ +vmPathName = "(.*)",.*?/\1/p'`
echo "VM with id ${vmid} has power state ${powerState} (name = ${name}; vmPathName = ${vmPathName})."
done
It uses vim-cmd vmsvc/getallvms, vim-cmd vmsvc/power.getstate and vim-cmd vmsvc/get.config with some sed and a for loop from dash to generate a nice list of information.
A long time ago, I already figured out that vim-cmd vmsvc/get.guest # gives all guest information including network information for a running VM that has either VMware Tools or open-vm-tools running (see VMware ESXi console: viewing all VMs, suspending and waking them up: part 3 for the difference between these two tools).
A full output of a sample VM is below the signature.
There are a few places that have the LAN ipAddress. For now, I choose to use only the IPv4 main address from ipAddress, which is in between (vim.vm.GuestInfo) { and net = (vim.vm.GuestInfo.NicInfo) [.
I modified the above script to become this:
Read the rest of this entry »
Posted in *nix, *nix-tools, ash/dash, ash/dash development, Development, ESXi6, ESXi6.5, ESXi6.7, ESXi7, find, Power User, Scripting, sed, sed script, Software Development, Virtualization, VMware, VMware ESXi | Leave a Comment »
Posted by jpluimers on 2021/10/26
I needed a way to append the directory of a script to the path as all my tool scripts are in there, and I did not want to modify any profile scripts as these might be modified during ESXi upgrade.
First you need the full script filename through readlink then toe parent directory name through dirname:
Note there might be dragons with more symlinks or different shells:
I created the script below. It is not perfect, but for my situation it gets the job done.
If you do not start a new shell, then the export is lost as a new dash shell process is started for each script that runs from the terminal or console.
# cat /opt/bin/append-script-directory-to-path-and-start-new-shell.sh
#!/bin/sh
# Absolute path to this script, e.g. /home/user/bin/foo.sh
# echo "'$0'"
SCRIPT=$(readlink -f "$0")
# Absolute path this script is in, thus /home/user/bin
SCRIPTPATH=$(dirname "$SCRIPT")
# echo Appending to $PATH: $SCRIPTPATH
export PATH=$PATH:$SCRIPTPATH
sh
–jeroen
Posted in *nix, *nix-tools, ash/dash, ash/dash development, Development, ESXi6, ESXi6.5, ESXi6.7, ESXi7, Power User, Scripting, Software Development, Virtualization, VMware, VMware ESXi | Leave a Comment »