Shell Scripting

Shellp Programmierung, Pattern Matching, Kornshell, Regular Expressions

  • Korn Shell / Bash,  ollama,  Uncategorized,  Windows Bash,  WSL

    Upgrading Ollama for Copilot Support: The Step you probably Miss

    Ollama recently added a built-in Copilot integration — but only from a certain version onwards. If your installation is older, you’ll get a confusing error before you even get started. Here’s exactly what happened when I upgraded, including the one gotcha that tripped me up along the way. The Starting Point: An Unsupported Version I wanted to launch Ollama’s new Copilot feature with the kimi-k2.5:cloud model. The command looked straightforward: The error made it clear: my version of Ollama simply didn’t know what copilot was. A quick version check confirmed the problem: Version 0.17.7 — too old for Copilot. Time to upgrade. Running the Upgrade Ollama’s official upgrade method is…

  • ansible,  Korn Shell / Bash,  Security

    Keeping an Eye on SSH Keys: Easily Review authorized_keys with awk

    Hello fellow Admins! Who hasn’t been there? The ~/.ssh/authorized_keys file is a crucial component for the security of your servers. But sometimes, especially when many keys are stored or very long keys are in use, the file can quickly become overwhelming. Getting a quick overview without endlessly scrolling through lengthy character strings is truly golden. That’s precisely why I have a small but powerful tip for you: an awk script that makes your authorized_keys more readable by shortening the SSH keys to a manageable length, without losing any vital information. Why is this useful? The awk Magic (Ansible-Aware!) This awk script shortens the actual SSH keys (the second column) to…

  • Korn Shell / Bash,  PowerShell,  Shell Scripting,  Windows Bash

    💡How to Extract Specific Lines from a File: sed, awk, head/tail, grep, and with powershell

    In the command line, it’s often necessary to extract only specific lines from a text file – whether it’s a single line or a range of lines. Fortunately, Bash offers several powerful tools for this. In this blog post, I’ll show you the most common methods using sed, awk, head/tail, and grep. Additionally, I will demonstrate an option when using PowerShell. Extracting Lines with sed sed (Stream EDitor) is a classic for text manipulation in the shell and is excellent for selectively outputting line ranges.Output a Single Line (e.g., Line 102)To output a specific line, such as line 102, you use the p command (print) in combination with the -n…

  • PowerShell,  Shell Scripting,  Uncategorized

    💡Powershell Tip – Search directories and subdirectories for files with specific content

    I’d like to share a small PowerShell script that scans all subdirectories for specific files (for example, *.yaml and *.yml) and searches them for a specific string (e.g., “ansible.builtin.template”). The result is returned with the location (name and path of the file, and line number of the search string in the file). What it does: Sometimes I want to save my results to a file and explore them further. To save the results to a CSV file, adapt the script as follows:

  • Middleware,  PowerShell

    Umbenennung von Dateien per powershell

    In Linux Umgebungen haben Administratoren für Logdateien von WebSphere Application Server, Tomcat und andere Middleware Produkte meist Skripte, um die Protokolle täglich oder wöchentlich umzubenennen (per crontab). Unter Windows habe ich auf die schnelle keine vernünftige Scriptlösung gefunden. Meine Lösung stelle ich in meinem Azure DevOps Projekt pwshLogSwitch zur Verfügung. Das kleine Script erwartet mindestens ein Startverzeichnis als Parameter. Alle Dateien in diesem Verzeichnis und darunter werden umbenannt, solange die Kriterien passen. Die Auswahlkriterien werden mit den Parametern -Filter -IncludePattern -ExcludePattern definiert und entsprechen den gleichnamigen Parametern von Get-ChildItem. Es können auch reguläre Ausdrücke und Wildcards übergeben werden. Als Verzeichnis können mehrere Verzeichnisnamen per : getrennt übergeben werden. IncludePattern und…

  • PowerShell

    💡Powershell Tip: Tail und Head vereint

    Ausgabe der letzten und der ersten n-Zeilen in einemBefehl In Unix/Linux Derivaten sind die Befehle tail und Head oft benutzte Werkzeuge zur Ausgabe der ersten/letzten Zeilen einer Datei oder der Ergebnisse eines Befehls. Direkt kombinieren kann man sie nicht. Hier sind sed/awk und andere Werkzeuge und Lösungen gefordert. Powershell bietet eine sehr effiziente Lösung. Der erste Ansatz wäre die Ausgabe mit Select -Last und Select -First zu behandeln. Das geht aber nicht in einem Befehl (oder nur mit einer zu schreibenden Funktion). Damit haben wir das gleiche Problem wie mit head und tail in Unix. Per Get-ChildItem und einem auf die Ausgabe angewendetem Sort Befehl erhält man eine Liste. Diese…

  • PowerShell,  Windows Bash,  WSL

    💡PowerShell Tip for Large Files – The Get-Content -Tail and -Wait parameters

    In PowerShell, you can display the last *n* lines of large text or ASCII files using the `-Tail` parameter of the `Get-Content` cmdlet: In Powershell, you can display the last *n* lines of large tyt or ASCII files using the -Tail parameter of the Get-Content cmdlet: Since PowerShell version 3, Get-Content (or its alias gc) includes the -Tail parameter. Unfortunately, there is no built-in equivalent to the Unix tail -f command for continuous updates. PowerShell: Get-Content with -Wait PowerShell’s Get-Content cmdlet supports the -Wait parameter, which continuously monitors a file for new content: This will display new lines as they are appended to the file. PowerShell with filtering (advanced usage)…