Command Line FU https://datastorageguy.com Consulting Services and Tech-Tips from Ben Patridge Tue, 10 Sep 2024 22:42:34 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.1 https://datastorageguy.com/wp-content/uploads/2025/11/cropped-dsgplatter-32x32.png Command Line FU https://datastorageguy.com 32 32 189268276 Using grep to search a file using multiple words as boolean AND OR condition https://datastorageguy.com/2024/09/10/using-grep-to-search-a-file-using-multiple-words-as-boolean-and-or-condition/ Tue, 10 Sep 2024 22:37:52 +0000 https://datastorageguy.com/?p=312

Command Overview

The following extended grep  (grep -E) example shows how to search a log files for

  1. Any line containing the words
    1. init
      AND
    2. SNMP OR tomcat 
  2. Any line containing either
    1. start_tomcat
      OR
    2. stop_tomcat
      OR
    3. start_snmp
      OR
    4. stop_snmp
  3. excluding any match with the word INT

Example

# grep -E "init.*(snmp|tomcat)|(start|stop)_(tomcat|snmp)" debug.log |grep -v INT 2024-09-10T13:54:36.686053-07:00 nec-6090-01#b stop_tomcat[4019]: running, pid file: /var/run/jsvc.pid , timeout interval: 15 secs 2024-09-10T13:54:36.687429-07:00 nec-6090-01#b stop_tomcat[4019]: pid: 1651 2024-09-10T13:54:36.704588-07:00 nec-6090-01#b stop_tomcat[4019]: init-+-AuthenticationS---7*[{Authentication}] 2024-09-10T13:54:36.705498-07:00 nec-6090-01#b stop_tomcat[4019]: |-HAMon---15*[{HAMon}] 2024-09-10T13:54:36.706346-07:00 nec-6090-01#b stop_tomcat[4019]: |-PlatMon---13*[{PlatMon}] 2024-09-10T13:54:36.707142-07:00 nec-6090-01#b stop_tomcat[4019]: |-ProcMon-+-realstore---98*[{realstore}] 2024-09-10T13:54:36.707881-07:00 nec-6090-01#b stop_tomcat[4019]: | 2024-09-10T13:54:36.708690-07:00 nec-6090-01#b stop_tomcat[4019]: `-9*[{ProcMon}] 2024-09-10T13:54:36.709454-07:00 nec-6090-01#b stop_tomcat[4019]: |-agetty 2024-09-10T13:54:36.710315-07:00 nec-6090-01#b stop_tomcat[4019]: |-cimserver---2*[{cimserver}] 2024-09-10T13:54:36.711077-07:00 nec-6090-01#b stop_tomcat[4019]: |-corewatch 2024-09-10T13:54:36.711792-07:00 nec-6090-01#b stop_tomcat[4019]: |-crond 2024-09-10T13:54:36.712541-07:00 nec-6090-01#b stop_tomcat[4019]: |-dbus-daemon 2024-09-10T13:54:36.713388-07:00 nec-6090-01#b stop_tomcat[4019]: |-java---21*[{java}] 2024-09-10T13:54:36.714237-07:00 nec-6090-01#b stop_tomcat[4019]: |-jsvc-+-jsvc 2024-09-10T13:54:36.714977-07:00 nec-6090-01#b stop_tomcat[4019]: | 2024-09-10T13:54:36.715776-07:00 nec-6090-01#b stop_tomcat[4019]: `-jsvc---62*[{jsvc}] 2024-09-10T13:54:36.716540-07:00 nec-6090-01#b stop_tomcat[4019]: |-jsvc-+-jsvc 2024-09-10T13:54:36.717367-07:00 nec-6090-01#b stop_tomcat[4019]: | 2024-09-10T13:54:36.718192-07:00 nec-6090-01#b stop_tomcat[4019]: `-jsvc---109*[{jsvc}] 2024-09-10T13:54:36.720254-07:00 nec-6090-01#b stop_tomcat[4019]: |-lldpd---lldpd 2024-09-10T13:54:36.721010-07:00 nec-6090-01#b stop_tomcat[4019]: |-6*[mingetty] 2024-09-10T13:54:36.721717-07:00 nec-6090-01#b stop_tomcat[4019]: |-ntpd---ntpd 2024-09-10T13:54:36.722473-07:00 nec-6090-01#b stop_tomcat[4019]: |-rpcbind 2024-09-10T13:54:36.723252-07:00 nec-6090-01#b stop_tomcat[4019]: |-rsyslogd-+-log_scrub.py 2024-09-10T13:54:36.724039-07:00 nec-6090-01#b stop_tomcat[4019]: | 2024-09-10T13:54:36.724822-07:00 nec-6090-01#b stop_tomcat[4019]: `-9*[{rsyslogd}] 2024-09-10T13:54:36.725621-07:00 nec-6090-01#b stop_tomcat[4019]: |-runuser---postmaster---18*[postmaster] 2024-09-10T13:54:36.726416-07:00 nec-6090-01#b stop_tomcat[4019]: |-runuser---postmaster---16*[postmaster] 2024-09-10T13:54:36.727143-07:00 nec-6090-01#b stop_tomcat[4019]: |-sh---stop_tomcat---pstree 2024-09-10T13:54:36.727860-07:00 nec-6090-01#b stop_tomcat[4019]: |-sshd-+-sshd---rsync.bin 2024-09-10T13:54:36.728562-07:00 nec-6090-01#b stop_tomcat[4019]: | 2024-09-10T13:54:36.729270-07:00 nec-6090-01#b stop_tomcat[4019]: `-sshd---bash---service---tomcat---initctl 2024-09-10T13:54:36.730039-07:00 nec-6090-01#b stop_tomcat[4019]: |-thriftshell---11*[{thriftshell}] 2024-09-10T13:54:36.730807-07:00 nec-6090-01#b stop_tomcat[4019]: |-udevd---2*[udevd] 2024-09-10T13:54:36.731537-07:00 nec-6090-01#b stop_tomcat[4019]: |-watchdog 2024-09-10T13:54:36.732229-07:00 nec-6090-01#b stop_tomcat[4019]: `-winbindd---winbindd 2024-09-10T13:54:37.735365-07:00 nec-6090-01#b stop_tomcat[4019]: Tomcat is stopped 2024-09-10T13:54:37.738757-07:00 nec-6090-01#b init[4098]: tomcat post-start 2024-09-10T13:54:39.366904-07:00 nec-6090-01#b start_tomcat[4097]: LOG-TOMCAT-0003: TASKSET options 2024-09-10T13:54:39.369087-07:00 nec-6090-01#b start_tomcat[4097]: Set JAVA options -Xms128M -Xmx2800M -XX:MaxMetaspaceSize=140M -XX:ReservedCodeCacheSize=140M -XX:+UseCodeCacheFlushing -Xss512k -XX:+UseStringDeduplication -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=*:5005 -XX:+PrintClassHistogram -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/corefiles -XX:ErrorFile=/var/corefiles/hs_err_pid<>.log -Dfile.encoding=UTF8 -Dcom.tintri.platform.productid=BR2 -Dhttps.protocols=TLSv1.2 -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false 2024-09-10T13:54:39.396222-07:00 nec-6090-01#b start_tomcat[4097]: Starting server using jsvc. 2024-09-10T13:55:11.215363-07:00 nec-6090-01#b stop_snmp[15117]: Stopping snmp agent 2024-09-10T13:55:12.217316-07:00 nec-6090-01#b stop_snmp[15117]: SNMP agent is stopped 2024-09-10T13:55:12.246235-07:00 nec-6090-01#b start_snmp[15416]: Set JAVA options -Xms64M -Xmx128M -XX:MaxMetaspaceSize=48M -XX:ReservedCodeCacheSize=48M -XX:+UseCodeCacheFlushing -Xss512k -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=*:5006 -XX:+UseStringDeduplication -XX:+PrintClassHistogram -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/corefiles -Dcom.tintri.platform.productid=BR2 -Dfile.encoding=UTF8 2024-09-10T13:55:12.247242-07:00 nec-6090-01#b start_snmp[15416]: Starting SNMP agent using jsvc. 2024-09-10T14:27:39.615636-07:00 nec-6090-01#b vmstore[2582]: HA: [2961] [tid 4996] HA-STATE: errorDetected: module [1], current state [104] indicates Error 2024-09-10T14:27:39.615698-07:00 nec-6090-01#b vmstore[2582]: HA: [2962] [tid 4996] HA-STATE: setStatusLocked: setting nodeRole to [SECONDARY], nodeStatus to [DISCONNECTED] 2024-09-10T14:27:39.690762-07:00 nec-6090-01#b vmstore[2582]: HA: [2967] [tid 5043] HA-STATE: errorDetected: module [5], current state [104] indicates Error 2024-09-10T14:27:40.191327-07:00 nec-6090-01#b vmstore[2582]: HA: [2969] [tid 5020] HA-STATE: setStatusLocked: setting nodeRole to [PRIMARY], nodeStatus to [SELECTED] 2024-09-10T14:27:40.312790-07:00 nec-6090-01#b vmstore[2582]: HA: [2970] [tid 2911] HA-STATE: disconnecting Secondary; becoming Primary 2024-09-10T14:27:40.313379-07:00 nec-6090-01#b vmstore[2582]: HA: [2980] [tid 2911] HA-STATE: notified HA modules to become Primary 2024-09-10T14:27:40.914011-07:00 nec-6090-01#b vmstore[2582]: HA: [3672] [tid 2911] HA-STATE: becomePrimary: invoked 2024-09-10T14:27:40.914059-07:00 nec-6090-01#b vmstore[2582]: HA: [3673] [tid 2911] HA-STATE: becomePrimary: eligible to be Primary due to NVRAM gen num [4] >= current disk gen num [4] 2024-09-10T14:27:40.914099-07:00 nec-6090-01#b vmstore[2582]: HA: [3674] [tid 2911] HA-STATE: updateGenNum: STARTUP: writing intended gen num [5] 2024-09-10T14:27:40.956406-07:00 nec-6090-01#b vmstore[2582]: HA: [3676] [tid 2911] HA-STATE: updateGenNum: writing NVRAM gen num as [5] 2024-09-10T14:27:40.999307-07:00 nec-6090-01#b vmstore[2582]: HA: [3681] [tid 2911] HA-STATE: setStatusLocked: setting nodeRole to [PRIMARY], nodeStatus to [RECOVERING] 2024-09-10T14:27:46.172490-07:00 nec-6090-01#b vmstore[2582]: HA: [7846] [tid 2911] HA-STATE: primaryBeginAccepting: invoked 2024-09-10T14:27:46.172972-07:00 nec-6090-01#b vmstore[2582]: HA: [7856] [tid 2911] HA-STATE: setStatusLocked: setting nodeRole to [PRIMARY], nodeStatus to [ACTIVE] 2024-09-10T14:27:46.173513-07:00 nec-6090-01#b vmstore[2582]: HA: [7868] [tid 746] HA-STATE: haManagerListenerThread: invoked 2024-09-10T14:28:46.213586-07:00 nec-6090-01#b vmstore[2582]: HA: [10685] [tid 746] HA-STATE: syncComplete: module [5] indicates SyncComplete 2024-09-10T14:28:47.113674-07:00 nec-6090-01#b vmstore[2582]: HA: [10815] [tid 4997] HA-STATE: syncComplete: module [1] indicates SyncComplete
]]>
312
Use sed to replace last character after matching a line https://datastorageguy.com/2024/05/14/use-sed-to-replace-last-character-after-matching-a-line/ Tue, 14 May 2024 21:08:19 +0000 https://datastorageguy.com/?p=308 If you are a coder like me we tend to discover after we have made a script that we need to change something on multiple lines.

Recently I have a script whereby added a "log_message" function which would echo a phrase.

However, I wanted to append a double parenthesis after the last character in the entire file.

For example.

Inside of myscript.sh I have the following

# grep Beginning myscript.sh
        log_message "Beginning function enableOrDisableRealstore"
        log_message "Beginning function modulePowerCycleChassis"
        log_message "Beginning function checkFipsLicense"
        log_message "Beginning function enableFips"
        log_message "Beginning function backupFips"
        log_message "FIPS: Beginning function isFipsEnabled"
        log_message "Beginning function isEncryptionEnabled"
        log_message "Beginning function isControllerPrimary"
        log_message "Beginning function isPeerControllerUpAndExecuting"
        log_message "Beginning function preZeroizeControllersValidation"
        log_message "Beginning function preZeroizeHaValidation"
        log_message "Beginning function preZeroizeDataCollection"
        log_message "Beginning function validateMachine"
        log_message "Beginning function cleanupDatabases"
        log_message "Beginning function isTxosRunning"
        log_message "Beginning function cleanupTunables"
        log_message "Beginning function checkControllerFailLogs"
        log_message "Beginning function getNetworkInfo"
        log_message "Beginning function getMDRaidInfo"
        log_message "Beginning function eraseSsdZion"
        log_message "Beginning function secureEraseSsd"
        log_message "Beginning function _retry_secerase for $disk"
        log_message "Beginning function _powercycle_disk_slot for $disk"
        log_message "Beginning function check_dd_process"
        log_message "Beginning function writeZeroesToHdd"
        log_message "Beginning function verifyBootDomPartition"
        log_message "Beginning function listDOM"
        log_message "Beginning function makePartitionsOnSSD"
        log_message "Beginning function formatRealstore"
        log_message "Beginning function updateDiskSignature"
        log_message "Beginning function deleteLogsAndCores"
        log_message "Beginning function resetRootPassword_default"
        log_message "Beginning function resetRootPassword_internal"
        log_message "Beginning function resetRootPassword"
        log_message "Beginning function resetAdminPasswordToSerialNumber"
        log_message "Beginning function validateSerialNumber"

My goal was to replace the last quote with ()" so that each line would look like

log_message "Beginning function validateSerialNumber()"

This is easily resolved using sed!

# sed -i.bak 's/\(.*Beginning.*\)[^ ]$/\1\(\)\"/' myscript.sh

the above backs up myscript.sh to myscript.sh.bak

Then it replaces the last quote with ()"

The result is

# grep Beginn myscript.sh
        log_message "Beginning function enableOrDisableRealstore()"
        log_message "Beginning function modulePowerCycleChassis()"
        log_message "Beginning function checkFipsLicense()"
        log_message "Beginning function enableFips()"
        log_message "Beginning function backupFips()"
        log_message "FIPS: Beginning function isFipsEnabled()"
        log_message "Beginning function isEncryptionEnabled()"
        log_message "Beginning function isControllerPrimary()"
        log_message "Beginning function isPeerControllerUpAndExecuting()"
        log_message "Beginning function preZeroizeControllersValidation()"
        log_message "Beginning function preZeroizeHaValidation()"
        log_message "Beginning function preZeroizeDataCollection()"
        log_message "Beginning function validateMachine()"
        log_message "Beginning function cleanupDatabases()"
        log_message "Beginning function isTxosRunning()"
        log_message "Beginning function cleanupTunables()"
        log_message "Beginning function checkControllerFailLogs()"
        log_message "Beginning function getNetworkInfo()"
        log_message "Beginning function getMDRaidInfo()"
        log_message "Beginning function eraseSsdZion()"
        log_message "Beginning function secureEraseSsd()"
        log_message "Beginning function _retry_secerase for $disk()"
        log_message "Beginning function _powercycle_disk_slot for $disk()"
        log_message "Beginning function check_dd_process()"
        log_message "Beginning function writeZeroesToHdd()"
        log_message "Beginning function verifyBootDomPartition()"
        log_message "Beginning function listDOM()"
        log_message "Beginning function makePartitionsOnSSD()"
        log_message "Beginning function formatRealstore()"
        log_message "Beginning function updateDiskSignature()"
        log_message "Beginning function deleteLogsAndCores()"
        log_message "Beginning function resetRootPassword_default()"
        log_message "Beginning function resetRootPassword_internal()"
        log_message "Beginning function resetRootPassword()"
        log_message "Beginning function resetAdminPasswordToSerialNumber()"
        log_message "Beginning function validateSerialNumber()"
]]>
308
Viewing contents of an open filehandle on a deleted file https://datastorageguy.com/2024/05/01/viewing-contents-of-an-open-filehandle-on-a-deleted-file/ Wed, 01 May 2024 22:35:32 +0000 https://datastorageguy.com/?p=305 There are times when you may unintentionally delete a file which is being written to.

When this occurs it will leave an Open Filehandle.

In Linux open filehandles may be viewed via the 'lsof' command.

# lsof +L1

In the following example here was the situation.

  1. I executed a script using nohup
    (i.e.   "nohup vmstore-tnt.sh  &")   
  2. File /root/nohup.out was being written to.
  3. I deleted the file nohup.out
  4. Thus this left an open filehandle.
$ lsof +L1
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NLINK    NODE NAME
vmstore-t 57520 root    1w   REG  252,1    26136     0 1671175 /root/nohup.out (deleted)
vmstore-t 57520 root    2w   REG  252,1    26136     0 1671175 /root/nohup.out (deleted)

Merely recreating the file via (touch /root/nohup.out) will not restore the file

To view the contents of the file that was deleted, you have to locate the Process ID (PID) from the above 'lsof' output.

(The above shows the PID as 57520)

Now wee can look for the fd (file descriptors) in Linux /proc pseudo filesystem by looking in /proc/<pid>/fd

# ls /proc/57520/fd
0  1  2  255
NUMBER MEANING
0Standard Input
1Standard Output
2Standard Error
255The File

*note: There may be additional File Descriptor Numbers which are beyond  the scope of this document.

Now, to view the real-time file progress you may issue

# cat /proc/57520/fd/1

To view any standard error  real-time you may view

# cat /proc/57520/fd/2

If you wish to temporarily restore the standard output of the file so you can monitor the output, you may create a 'soft' link via:

# ln -s /proc/57520/fd/1  /root/nohup.out

You may verify the link via

$ ls -Al nohup.out
lrwxrwxrwx 1 root root    16 May  1 15:02 nohup.out -> /proc/57520/fd/1

*note: Once the process stops you will have to delete the soft link!

When you try to view the contents you will see

# tail nohup.out
tail: cannot open `nohup.out' for reading: No such file or directory

Therefore remove the file

# rm nohup.out

We should no longer see any open files

# lsof +L1
#
]]>
305
Cscope search results are invisible https://datastorageguy.com/2024/02/13/cscope-search-results-are-invisible/ Tue, 13 Feb 2024 21:58:59 +0000 https://datastorageguy.com/?p=286 Part of my 'day job' is trolling thru source code when looking for answers. My preferred mechanism, other than a recursive grep, is to use cscope

Cscope is a useful tool for searching a source code tree after you build a list of files to search

The Problem

However, in this conundrum, when I would use any of the search options within cscope the File list (or list of source files) was empty, blank, envisible... basically, I could not SEE any of the results!

Example

Recreating the issue

In the following example, I built a list of files so that I could populate cscope

# cd /export/hg/default/pstoolkit
# find PstkCore/ -type f -not -path "*__In*" -not -path "*__Out*" -not -path "*ThirdPart*" -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.hpp" -o -name "*.cs*" > cscope.files

Then I read the results into cscope

# ls -al cscope.files
-rw-rw-r-- 1 bpatridge bpatridge 77196 Feb 13 12:46 cscope.files
# cscope -q -R -b -i cscope.files
# 

Now I attempt to open cscope

# cscope -d

Now I see the window:

However,

When I search for string "TimeOfDay" the search results are invisible?

I even attempted to change the colors but the results were the same

Oddly enough, when I scroll down and press enter I CAN still view one of the source files?

However when I return it is still empty.

The Solution

The solution in this case was surprising.

I trolled the internet for weeks until I finally found a nugget on old ye faithful - stackoverflow which mentioned that cscope has problems with control characters!

I noted when viewing the contents of several files there was a ^M appended to each line.

Therefore I ran dos2unix on all of the files in cscope.files

# cat cscope.files |xargs -n1 -I{}  dos2unix  {}
dos2unix: converting file PstkCore/dotnetSDK/src/SDK/Tintri.Types/Generated/SraPeerArray.cs to Unix format ...
dos2unix: converting file PstkCore/dotnetSDK/src/SDK/Tintri.Types/Generated/SraPrepareReverseReplicationResponse.cs to Unix format ...
dos2unix: converting file PstkCore/dotnetSDK/src/SDK/Tintri.Types/Generated/RecommendationSpaceOutcome.cs to Unix format ...
dos2unix: converting file PstkCore/dotnetSDK/src/SDK/Tintri.Types/Generated/RemoteCopyInfo.cs to Unix format ...
dos2unix: converting file PstkCore/dotnetSDK/src/SDK/Tintri.Types/Generated/ReplLinkStat.cs to Unix format ...
dos2unix: converting file PstkCore/dotnetSDK/src/SDK/Tintri.Types/Generated/ReplicationStat.cs to Unix format ...
dos2unix: converting file PstkCore/dotnetSDK/src/SDK/Tintri.Types/Generated/RestApi.cs to Unix format ...
dos2unix: converting file PstkCore/dotnetSDK/src/SDK/Tintri.Types/Generated/RestApiPrivilege.cs to Unix format ...
dos2unix: converting file PstkCore/dotnetSDK/src/SDK/Tintri.Types/Generated/RestoreInfo.cs to Unix format ...
dos2unix: converting file PstkCore/dotnetSDK/src/SDK/Tintri.Types/Generated/ServiceGroup.cs to Unix format ...
dos2unix: converting file PstkCore/dotnetSDK/src/SDK/Tintri.Types/Generated/ServiceGroupOperationStatus.cs to Unix format ...
dos2unix: converting file PstkCore/dotnetSDK/src/SDK/Tintri.Types/Generated/Severity.cs to Unix format ...
....

After this was complete, I was able to run cscope normally and now I can see the search results!!!


]]>
286
Display ethernet devices on a Fedora system using the Linux Pseudo Filesystem and create a static IP Address https://datastorageguy.com/2023/09/11/display-ethernet-devices-on-a-fedora-system-using-the-linux-pseudo-filesystem-and-create-a-static-ip-address/ Mon, 11 Sep 2023 21:56:31 +0000 https://datastorageguy.com/?p=267 Encountered a fun riddle recently whereby on a Fedora 34 system I needed to locate all ethernet interfaces on a system that are obtaining a DHCP address, then after the first reboot create a static IP address.

I am a big fan of looking thru the Linux pseudo filesystem in /sys

In this instance I wanted to exclude any Virtual, Bridge and Local Interfaces.

Therefore I do the following:

Listing all Interfaces in sysfs

# ls /sys/class/net|egrep -v "^vir|^lo|^wl|^br"

Example

# ls /sys/class/net|egrep -v "^vir|^lo|^wl|^br"
eno1

PART 1 - CHANGE FROM DHCP TO STATIC IP ADDRESS

To change from DHCP to a STATIC IP Address

First display the current interfaces

# nmcli con show
NAME    UUID                                  TYPE      DEVICE
enp1s0  46145016-ead7-4128-8d91-4b0b828162db  ethernet  enp1s0

and to set a STATIC IP with NAME "System-NIC-110" the format would be

# nmcli con add con-name "System-NIC-110" ifname enp1s0 type ethernet ip4 192.168.122.110/24 gw4 192.168.122.1

Then you would delete the original interface afterwards

# nmcli con del enp1s0

Then either reboot or restart networking

# nmcli networking off
# nmcli networking on

Now you will see the new interface name.

# nmcli con show
NAME            UUID                                  TYPE      DEVICE
System-NIC-110  fc1ca250-1481-4014-82bd-ad97d1c48ae4  ethernet  enp1s0

PART II - Script method to change all interfaces after first reboot

Here is a script example how to iterate thru all devices on the system and create static IP addresses:

#!/bin/bash
###################################################################
# SCRIPT BY The Data Storage Guy (https://datastorageguy.com)
# As an example how iterate thru all ethernet devices on a Fedora
# system and assign Static IP Addresses with a custom name
#
# location: /usr/local/bin/set-static-ip.sh
###################################################################
# The following will go thru all of the ethernet devices found
#
# It is used to on create static IP addresses with connection NAME
#
# $connection_prefix-$starting_octet
#
# with IP address using the format
#
# $ip_subnet.$starting_octet
#
# It will also increment should there be more
# than one ethernet device found
#
# the parameters are used within the following configuration file
###################################################################
connection_prefix="System-NIC"
ip_subnet="192.168.122"
starting_octet="110"
mask="24"
gateway="192.168.122.1"
###################################################################
PS4='${LINENO}: '
###################################################################
SCRIPT=$(basename ${BASH_SOURCE[0]})
###################################################################
export PATH=$PATH:/usr/bin/
log=/var/log/$(echo $SCRIPT|cut -d. -f1).log
line="-----------------------------------------------"
step=1
n=1
###################################################################
logm() {
        LOGDATE=`date '+%Y-%m-%dT%H:%M:%S'`
        echo $line |tee -a $log
        echo "[$LOGDATE] [$step]  $1" |tee -a $log |tee >(logger -t $SCRIPT)
        ((step++))
}
###################################################################
logm "Displaying Network General Status"
logm "Issuing command: nmcli general status"
nmcli general status  >>$log

logm "Displaying Network Interfaces"
logm "Issuing command: nmcli con show"
nmcli con show |tee -a $log | logger -t $SCRIPT

while read ethname; do
        ip="${ip_subnet}.${starting_octet}"
        UUID=$(nmcli conn show |awk -v iface=$ethname '$NF ~ iface {print $(NF-2)}')
        logm "Setting $ethname ip address to ${ip}/24 with name "${connection_prefix}-$ip" for ethernet $ethname UUID=$UUID"
        logm "Issuing Command:  nmcli con add con-name "${connection_prefix}-$starting_octet" ifname $ethname type ethernet ip4 ${ip}/$mask gw4 $gateway"
        nmcli con add con-name "${connection_prefix}-$starting_octet" ifname $ethname type ethernet ip4 ${ip}/$mask gw4 $gateway  |tee -a $log
        if [ $? == 0 ]; then
                logm "Successfully added con-name ${connection_prefix}-$starting_octet"
        else
                logm "ERROR: Problem adding con-name ${connection_prefix}-$starting_octet"
        fi
        sleep .2
        logm "Deleting $ethname: nmcli con del $ethname"
        logm "Issuing command: nmcli con del $ethname"
        nmcli con del $ethname |tee -a $log
        if [ $? == 0 ]; then
                logm "Successfully deleted $ethname: nmcli con del $ethname"
        else
                logm "ERROR: Unable to delete $ethname: nmcli con del $ethname"
        fi
        ((n++))
        ((starting_octet++))
done< <(ls /sys/class/net|egrep -v "^vir|^lo|^wl|^br")

logm "Displaying Network Interfaces"
logm "Issuing command: nmcli con show"
nmcli con show |tee -a $log |logger -t $SCRIPT

logm "Checking for the install cron job entry"
logm "Issuing command: crontab -l"
crontab -l |tee -a $log|logger -t $SCRIPT

logm "Restarting Network Services"
logm "Issuing command: nmcli networking off"
nmcli networking off |tee -a $log
sleep .2
logm "Issuing command: nmcli networking on"
nmcli networking on |tee -a $log
sleep 2
logm "Displaying Network Interfaces"
logm "Issuing command: ncmli con show"
nmcli con show |tee -a $log |logger -t $SCRIPT

if [ $(nmcli con show|grep -q $connection_prefix;echo $?) == 0 ]; then
        logm "GOOD: Found $connection_prefix Network Device"
        crontab -l |tee -a $log
        if [ $? == 0 ]; then
                logm "Sleeping for 15 seconds... then removing cron job"
                sleep 15
                logm "Removing cron jobs"
                logm "Issuing command: crontab -r"
                crontab -r &>/dev/null
        fi
else
        logm "ERROR: Unable to find $connection_prefix Network device"
fi


logm "Completed Network Setting Setup"
###################################################################

Now we create a cron entry to run only at reboot and log to /root/cron.log

@reboot  /usr/bin/bash /usr/local/bin/set-static-ip.sh >> /root/cron.log

Now when we reboot we see the new network settings.

# nmcli con show
NAME            UUID                                  TYPE      DEVICE
System-NIC-110  62a904ab-2be2-4223-bc13-0b7daba2409e  ethernet  enp1s0
System-NIC-111  350008d7-f075-4ca5-ad97-f5ba8e6f20d0  ethernet  enp7s0

The /var/log/set-static-ip.log shows the following script steps

# cat /var/log/set-static-ip.log
-----------------------------------------------
[2023-09-11T13:28:20] [1]  Displaying Network General Status
-----------------------------------------------
[2023-09-11T13:28:20] [2]  Issuing command: nmcli general status
STATE                  CONNECTIVITY  WIFI-HW  WIFI     WWAN-HW  WWAN
connected (site only)  limited       enabled  enabled  enabled  enabled
-----------------------------------------------
[2023-09-11T13:28:20] [3]  Displaying Network Interfaces
-----------------------------------------------
[2023-09-11T13:28:20] [4]  Issuing command: nmcli con show
NAME    UUID                                  TYPE      DEVICE
enp1s0  197a76a0-a28a-4db4-8e64-a90557e47c9f  ethernet  enp1s0
enp7s0  d0cf6083-8f35-4be1-8705-95ac804eecac  ethernet  enp7s0
-----------------------------------------------
[2023-09-11T13:28:20] [5]  Setting enp1s0 ip address to 192.168.122.110/24 with name System-NIC-192.168.122.110 for ethernet enp1s0 UUID=197a76a0-a28a-4db4-8e64-a90557e47c9f
-----------------------------------------------
[2023-09-11T13:28:20] [6]  Issuing Command:  nmcli con add con-name System-NIC-110 ifname enp1s0 type ethernet ip4 192.168.122.110/24 gw4 192.168.122.1
Connection 'System-NIC-110' (6bd11875-8971-41d0-9089-c3caebc02bb0) successfully added.
-----------------------------------------------
[2023-09-11T13:28:20] [7]  Successfully added con-name System-NIC-110
-----------------------------------------------
[2023-09-11T13:28:20] [8]  Deleting enp1s0: nmcli con del enp1s0
-----------------------------------------------
[2023-09-11T13:28:20] [9]  Issuing command: nmcli con del enp1s0
Connection 'enp1s0' (197a76a0-a28a-4db4-8e64-a90557e47c9f) successfully deleted.
-----------------------------------------------
[2023-09-11T13:28:20] [10]  Successfully deleted enp1s0: nmcli con del enp1s0
-----------------------------------------------
[2023-09-11T13:28:20] [11]  Setting enp7s0 ip address to 192.168.122.111/24 with name System-NIC-192.168.122.111 for ethernet enp7s0 UUID=d0cf6083-8f35-4be1-8705-95ac804eecac
-----------------------------------------------
[2023-09-11T13:28:20] [12]  Issuing Command:  nmcli con add con-name System-NIC-111 ifname enp7s0 type ethernet ip4 192.168.122.111/24 gw4 192.168.122.1
Connection 'System-NIC-111' (8eee96f7-8a42-4bb4-b57a-e15d222743f1) successfully added.
-----------------------------------------------
[2023-09-11T13:28:20] [13]  Successfully added con-name System-NIC-111
-----------------------------------------------
[2023-09-11T13:28:20] [14]  Deleting enp7s0: nmcli con del enp7s0
-----------------------------------------------
[2023-09-11T13:28:20] [15]  Issuing command: nmcli con del enp7s0
Connection 'enp7s0' (d0cf6083-8f35-4be1-8705-95ac804eecac) successfully deleted.
-----------------------------------------------
[2023-09-11T13:28:20] [16]  Successfully deleted enp7s0: nmcli con del enp7s0
-----------------------------------------------
[2023-09-11T13:28:20] [17]  Displaying Network Interfaces
-----------------------------------------------
[2023-09-11T13:28:20] [18]  Issuing command: nmcli con show
NAME            UUID                                  TYPE      DEVICE
System-NIC-110  6bd11875-8971-41d0-9089-c3caebc02bb0  ethernet  enp1s0
System-NIC-111  8eee96f7-8a42-4bb4-b57a-e15d222743f1  ethernet  enp7s0
virbr0          02b8c655-36de-4379-b096-b48de5941117  bridge    virbr0
-----------------------------------------------
[2023-09-11T13:28:21] [19]  Checking for the install cron job entry
-----------------------------------------------
[2023-09-11T13:28:21] [20]  Issuing command: crontab -l
@reboot  /usr/bin/bash /usr/local/bin/set-static-ip.sh >> /root/cron.log
-----------------------------------------------
[2023-09-11T13:28:21] [21]  Restarting Network Services
-----------------------------------------------
[2023-09-11T13:28:21] [22]  Issuing command: nmcli networking off
-----------------------------------------------
[2023-09-11T13:28:21] [23]  Issuing command: nmcli networking on
-----------------------------------------------
[2023-09-11T13:28:21] [24]  Displaying Network Interfaces
-----------------------------------------------
[2023-09-11T13:28:21] [25]  Issuing command: ncmli con show
NAME            UUID                                  TYPE      DEVICE
System-NIC-110  6bd11875-8971-41d0-9089-c3caebc02bb0  ethernet  enp1s0
System-NIC-111  8eee96f7-8a42-4bb4-b57a-e15d222743f1  ethernet  enps7
-----------------------------------------------
[2023-09-11T13:28:21] [26]  GOOD: Found System-NIC Network Device
@reboot  /usr/bin/bash /usr/local/bin/set-static-ip.sh >> /root/cron.log
-----------------------------------------------
[2023-09-11T13:28:21] [27]  Sleeping for 15 seconds... then removing cron job
-----------------------------------------------
[2023-09-11T13:28:36] [28]  Removing cron jobs
-----------------------------------------------
[2023-09-11T13:28:36] [29]  Issuing command: crontab -r
-----------------------------------------------
[2023-09-11T13:28:36] [30]  Completed Network Setting Setup
]]>
267
Downloading an RPM package including all of its dependencies on Fedora https://datastorageguy.com/2023/09/08/downloading-an-rpm-package-including-all-of-its-dependencies-on-fedora/ Fri, 08 Sep 2023 20:55:28 +0000 https://datastorageguy.com/?p=259 There are times when you need to fully download an RPM and all of its dependencies.


However,

If you have already downloaded the RPM re-downloading the RPM and all its dependencies can be very difficult.

I have found the following is a way to use an alternate installation 'root' directory so that you can ensure you are not using your system RPM database, and you can download all of the dependencies for the package.

In the following example I

  1. Create an "/installroot" directory
  2. Create a directory called /data/repo/terminator to store the downloaded RPM and its dependencies
  3. Download the 'terminator' package for fedora 34
# mkdir /installroot
# mkdir /data/repo/terminator
# dnf -y install --installroot=/instroot --downloaddir=/data/repo/terminator --downloadonly --noautoremove --releasever=34 terminator

The results will look like the following!

# ls /data/repo/terminator/
acl-2.3.1-1.fc34.x86_64.rpm
adwaita-cursor-theme-40.1.1-1.fc34.noarch.rpm
adwaita-icon-theme-40.1.1-1.fc34.noarch.rpm
alsa-lib-1.2.6.1-3.fc34.x86_64.rpm
alternatives-1.15-2.fc34.x86_64.rpm
atk-2.36.0-3.fc34.x86_64.rpm
at-spi2-atk-2.38.0-2.fc34.x86_64.rpm
at-spi2-core-2.40.3-1.fc34.x86_64.rpm
audit-libs-3.0.6-1.fc34.x86_64.rpm
avahi-libs-0.8-14.fc34.x86_64.rpm
basesystem-11-11.fc34.noarch.rpm
bash-5.1.0-2.fc34.x86_64.rpm
bzip2-libs-1.0.8-6.fc34.x86_64.rpm
ca-certificates-2021.2.52-1.0.fc34.noarch.rpm
cairo-1.17.4-3.fc34.x86_64.rpm
cairo-gobject-1.17.4-3.fc34.x86_64.rpm
colord-libs-1.4.5-2.fc34.x86_64.rpm
coreutils-8.32-32.fc34.x86_64.rpm
coreutils-common-8.32-32.fc34.x86_64.rpm
cpio-2.13-10.fc34.x86_64.rpm
cracklib-2.9.6-27.fc34.x86_64.rpm
crypto-policies-20210213-1.git5c710c0.fc34.noarch.rpm
crypto-policies-scripts-20210213-1.git5c710c0.fc34.noarch.rpm
cryptsetup-libs-2.3.7-1.fc34.x86_64.rpm
cups-libs-2.3.3op2-17.fc34.x86_64.rpm
curl-7.76.1-12.fc34.x86_64.rpm
cyrus-sasl-lib-2.1.27-9.fc34.x86_64.rpm
dbus-1.12.20-3.fc34.x86_64.rpm
dbus-broker-29-2.fc34.x86_64.rpm
dbus-common-1.12.20-3.fc34.noarch.rpm
dbus-libs-1.12.20-3.fc34.x86_64.rpm
dconf-0.40.0-3.fc34.x86_64.rpm
dejavu-sans-fonts-2.37-16.fc34.noarch.rpm
device-mapper-1.02.175-1.fc34.x86_64.rpm
device-mapper-libs-1.02.175-1.fc34.x86_64.rpm
diffutils-3.7-8.fc34.x86_64.rpm
dracut-055-6.fc34.x86_64.rpm
elfutils-debuginfod-client-0.186-1.fc34.x86_64.rpm
elfutils-default-yama-scope-0.186-1.fc34.noarch.rpm
elfutils-libelf-0.186-1.fc34.x86_64.rpm
elfutils-libs-0.186-1.fc34.x86_64.rpm
expat-2.4.7-1.fc34.x86_64.rpm
fedora-gpg-keys-34-2.noarch.rpm
fedora-release-34-39.noarch.rpm
fedora-release-common-34-39.noarch.rpm
fedora-release-identity-basic-34-39.noarch.rpm
fedora-repos-34-2.noarch.rpm
file-5.39-7.fc34.x86_64.rpm
file-libs-5.39-7.fc34.x86_64.rpm
filesystem-3.14-5.fc34.x86_64.rpm
findutils-4.8.0-2.fc34.x86_64.rpm
flac-libs-1.3.3-7.fc34.x86_64.rpm
fontconfig-2.13.94-5.fc34.x86_64.rpm
fonts-filesystem-2.0.5-5.fc34.noarch.rpm
freetype-2.10.4-3.fc34.x86_64.rpm
fribidi-1.0.11-3.fc34.x86_64.rpm
fuse-libs-2.9.9-11.fc34.x86_64.rpm
gawk-5.1.0-3.fc34.x86_64.rpm
gawk-all-langpacks-5.1.0-3.fc34.x86_64.rpm
gdbm-libs-1.19-2.fc34.x86_64.rpm
gdk-pixbuf2-2.42.6-1.fc34.x86_64.rpm
gdk-pixbuf2-modules-2.42.6-1.fc34.x86_64.rpm
gettext-0.21-4.fc34.x86_64.rpm
gettext-libs-0.21-4.fc34.x86_64.rpm
glib2-2.68.4-1.fc34.x86_64.rpm
glibc-2.33-21.fc34.x86_64.rpm
glibc-common-2.33-21.fc34.x86_64.rpm
glibc-doc-2.33-21.fc34.noarch.rpm
glibc-minimal-langpack-2.33-21.fc34.x86_64.rpm
gmp-6.2.0-6.fc34.x86_64.rpm
gnutls-3.7.4-1.fc34.x86_64.rpm
gobject-introspection-1.68.0-4.fc34.x86_64.rpm
graphite2-1.3.14-7.fc34.x86_64.rpm
grep-3.6-2.fc34.x86_64.rpm
grub2-common-2.06-9.fc34.noarch.rpm
grub2-tools-2.06-9.fc34.x86_64.rpm
grub2-tools-minimal-2.06-9.fc34.x86_64.rpm
grubby-8.40-51.fc34.x86_64.rpm
gsm-1.0.19-5.fc34.x86_64.rpm
gstreamer1-1.19.1-2.1.18.4.fc34.x86_64.rpm
gtk3-3.24.30-1.fc34.x86_64.rpm
gtk-update-icon-cache-3.24.30-1.fc34.x86_64.rpm
gzip-1.10-5.fc34.x86_64.rpm
harfbuzz-2.7.4-3.fc34.x86_64.rpm
hicolor-icon-theme-0.17-10.fc34.noarch.rpm
iptables-legacy-libs-1.8.7-8.fc34.x86_64.rpm
jbigkit-libs-2.1-21.fc34.x86_64.rpm
json-c-0.14-8.fc34.x86_64.rpm
kbd-2.4.0-2.fc34.x86_64.rpm
kbd-misc-2.4.0-2.fc34.noarch.rpm
keybinder3-0.3.2-11.fc34.x86_64.rpm
keyutils-libs-1.6.1-2.fc34.x86_64.rpm
kmod-29-2.fc34.x86_64.rpm
kmod-libs-29-2.fc34.x86_64.rpm
kpartx-0.8.5-4.fc34.x86_64.rpm
krb5-libs-1.19.2-5.fc34.x86_64.rpm
langpacks-core-font-en-3.0-14.fc34.noarch.rpm
lcms2-2.12-1.fc34.x86_64.rpm
libacl-2.3.1-1.fc34.x86_64.rpm
libarchive-3.5.2-2.fc34.x86_64.rpm
libargon2-20171227-6.fc34.x86_64.rpm
libasyncns-0.8-20.fc34.x86_64.rpm
libattr-2.5.1-1.fc34.x86_64.rpm
libblkid-2.36.2-1.fc34.x86_64.rpm
libbpf-0.4.0-1.fc34.x86_64.rpm
libbrotli-1.0.9-4.fc34.x86_64.rpm
libcanberra-0.30-24.fc34.x86_64.rpm
libcanberra-gtk3-0.30-24.fc34.x86_64.rpm
libcap-2.48-2.fc34.x86_64.rpm
libcap-ng-0.8.2-4.fc34.x86_64.rpm
libcbor-0.7.0-3.fc34.x86_64.rpm
libcloudproviders-0.3.1-3.fc34.x86_64.rpm
libcom_err-1.45.6-5.fc34.x86_64.rpm
libcurl-7.76.1-12.fc34.x86_64.rpm
libdatrie-0.2.13-1.fc34.x86_64.rpm
libdb-5.3.28-49.fc34.x86_64.rpm
libeconf-0.4.0-1.fc34.x86_64.rpm
libepoxy-1.5.9-1.fc34.x86_64.rpm
libevent-2.1.12-3.fc34.x86_64.rpm
libfdisk-2.36.2-1.fc34.x86_64.rpm
libffi-3.1-28.fc34.x86_64.rpm
libfido2-1.6.0-2.fc34.x86_64.rpm
libgcc-11.3.1-2.fc34.x86_64.rpm
libgcrypt-1.9.3-3.fc34.x86_64.rpm
libgomp-11.3.1-2.fc34.x86_64.rpm
libgpg-error-1.42-1.fc34.x86_64.rpm
libgusb-0.3.8-1.fc34.x86_64.rpm
libibverbs-37.2-2.fc34.x86_64.rpm
libICE-1.0.10-6.fc34.x86_64.rpm
libicu-67.1-7.fc34.x86_64.rpm
libidn2-2.3.2-1.fc34.x86_64.rpm
libjpeg-turbo-2.0.90-3.fc34.x86_64.rpm
libkcapi-1.2.1-1.fc34.x86_64.rpm
libkcapi-hmaccalc-1.2.1-1.fc34.x86_64.rpm
libmount-2.36.2-1.fc34.x86_64.rpm
libnghttp2-1.43.0-2.fc34.x86_64.rpm
libnl3-3.5.0-6.fc34.x86_64.rpm
libnsl2-1.3.0-2.fc34.x86_64.rpm
libogg-1.3.4-4.fc34.x86_64.rpm
libpcap-1.10.1-1.fc34.x86_64.rpm
libpng-1.6.37-10.fc34.x86_64.rpm
libpsl-0.21.1-3.fc34.x86_64.rpm
libpwquality-1.4.4-6.fc34.x86_64.rpm
libseccomp-2.5.3-1.fc34.x86_64.rpm
libselinux-3.2-1.fc34.x86_64.rpm
libsemanage-3.2-1.fc34.x86_64.rpm
libsepol-3.2-2.fc34.x86_64.rpm
libsigsegv-2.13-2.fc34.x86_64.rpm
libSM-1.2.3-8.fc34.x86_64.rpm
libsmartcols-2.36.2-1.fc34.x86_64.rpm
libsndfile-1.0.31-6.fc34.x86_64.rpm
libssh-0.9.6-1.fc34.x86_64.rpm
libssh-config-0.9.6-1.fc34.noarch.rpm
libstdc++-11.3.1-2.fc34.x86_64.rpm
libtasn1-4.16.0-4.fc34.x86_64.rpm
libtdb-1.4.3-6.fc34.x86_64.rpm
libtextstyle-0.21-4.fc34.x86_64.rpm
libthai-0.1.28-6.fc34.x86_64.rpm
libtiff-4.2.0-1.fc34.x86_64.rpm
libtirpc-1.3.2-0.fc34.x86_64.rpm
libtool-ltdl-2.4.6-40.fc34.x86_64.rpm
libunistring-0.9.10-10.fc34.x86_64.rpm
libunwind-1.4.0-5.fc34.x86_64.rpm
libusbx-1.0.24-2.fc34.x86_64.rpm
libutempter-1.2.1-4.fc34.x86_64.rpm
libuuid-2.36.2-1.fc34.x86_64.rpm
libverto-0.3.2-1.fc34.x86_64.rpm
libvorbis-1.3.7-3.fc34.x86_64.rpm
libwayland-client-1.20.0-4.fc34.x86_64.rpm
libwayland-cursor-1.20.0-4.fc34.x86_64.rpm
libwayland-egl-1.20.0-4.fc34.x86_64.rpm
libwebp-1.2.2-1.fc34.x86_64.rpm
libX11-1.7.2-3.fc34.x86_64.rpm
libX11-common-1.7.2-3.fc34.noarch.rpm
libX11-xcb-1.7.2-3.fc34.x86_64.rpm
libXau-1.0.9-6.fc34.x86_64.rpm
libxcb-1.13.1-7.fc34.x86_64.rpm
libXcomposite-0.4.5-5.fc34.x86_64.rpm
libxcrypt-4.4.28-1.fc34.x86_64.rpm
libxcrypt-compat-4.4.28-1.fc34.x86_64.rpm
libXcursor-1.2.0-5.fc34.x86_64.rpm
libXdamage-1.1.5-5.fc34.x86_64.rpm
libXext-1.3.4-6.fc34.x86_64.rpm
libXfixes-6.0.0-1.fc34.x86_64.rpm
libXft-2.3.3-6.fc34.x86_64.rpm
libXi-1.7.10-6.fc34.x86_64.rpm
libXinerama-1.1.4-8.fc34.x86_64.rpm
libxkbcommon-1.3.0-1.fc34.x86_64.rpm
libxml2-2.9.13-1.fc34.x86_64.rpm
libXrandr-1.5.2-6.fc34.x86_64.rpm
libXrender-0.9.10-14.fc34.x86_64.rpm
libXtst-1.2.3-14.fc34.x86_64.rpm
libzstd-1.5.2-1.fc34.x86_64.rpm
lua-libs-5.4.4-1.fc34.x86_64.rpm
lz4-libs-1.9.3-2.fc34.x86_64.rpm
memstrack-0.2.2-1.fc34.x86_64.rpm
mkpasswd-5.5.10-1.fc34.x86_64.rpm
mpfr-4.1.0-7.fc34.x86_64.rpm
ncurses-6.2-4.20200222.fc34.x86_64.rpm
ncurses-base-6.2-4.20200222.fc34.noarch.rpm
ncurses-libs-6.2-4.20200222.fc34.x86_64.rpm
nettle-3.7.3-1.fc34.x86_64.rpm
openldap-2.4.57-6.fc34.x86_64.rpm
openssl-libs-1.1.1n-1.fc34.x86_64.rpm
openssl-pkcs11-0.4.11-2.fc34.x86_64.rpm
opus-1.3.1-8.fc34.x86_64.rpm
os-prober-1.77-7.fc34.x86_64.rpm
p11-kit-0.23.22-3.fc34.x86_64.rpm
p11-kit-trust-0.23.22-3.fc34.x86_64.rpm
pam-1.5.1-8.fc34.x86_64.rpm
pango-1.48.11-1.fc34.x86_64.rpm
pcre2-10.36-4.fc34.x86_64.rpm
pcre2-syntax-10.36-4.fc34.noarch.rpm
pcre-8.44-3.fc34.1.x86_64.rpm
pigz-2.5-1.fc34.x86_64.rpm
pixman-0.40.0-3.fc34.x86_64.rpm
popt-1.18-4.fc34.x86_64.rpm
procps-ng-3.3.17-1.fc34.1.x86_64.rpm
publicsuffix-list-dafsa-20190417-5.fc34.noarch.rpm
pulseaudio-libs-14.2-3.fc34.x86_64.rpm
python3-3.9.12-1.fc34.x86_64.rpm
python3-cairo-1.20.1-1.fc34.x86_64.rpm
python3-configobj-5.0.6-23.fc34.noarch.rpm
python3-dbus-1.2.18-1.fc34.x86_64.rpm
python3-gobject-3.40.1-1.fc34.x86_64.rpm
python3-gobject-base-3.40.1-1.fc34.x86_64.rpm
python3-libs-3.9.12-1.fc34.x86_64.rpm
python3-pip-21.0.1-4.fc34.noarch.rpm
python3-psutil-5.8.0-5.fc34.x86_64.rpm
python3-setuptools-53.0.0-3.fc34.noarch.rpm
python3-six-1.15.0-5.fc34.noarch.rpm
python-pip-wheel-21.0.1-4.fc34.noarch.rpm
python-setuptools-wheel-53.0.0-3.fc34.noarch.rpm
python-unversioned-command-3.9.12-1.fc34.noarch.rpm
qrencode-libs-4.1.1-1.fc34.x86_64.rpm
readline-8.1-2.fc34.x86_64.rpm
rpm-4.16.1.3-1.fc34.x86_64.rpm
rpm-libs-4.16.1.3-1.fc34.x86_64.rpm
sed-4.8-7.fc34.x86_64.rpm
setup-2.13.7-3.fc34.noarch.rpm
shadow-utils-4.8.1-10.fc34.x86_64.rpm
shared-mime-info-2.1-2.fc34.x86_64.rpm
sound-theme-freedesktop-0.8-15.fc34.noarch.rpm
sqlite-libs-3.34.1-2.fc34.x86_64.rpm
systemd-248.10-1.fc34.x86_64.rpm
systemd-libs-248.10-1.fc34.x86_64.rpm
systemd-networkd-248.10-1.fc34.x86_64.rpm
systemd-pam-248.10-1.fc34.x86_64.rpm
systemd-rpm-macros-248.10-1.fc34.noarch.rpm
systemd-udev-248.10-1.fc34.x86_64.rpm
terminator-2.1.1-1.fc34.noarch.rpm
tpm2-tss-3.1.0-1.fc34.x86_64.rpm
tzdata-2022a-1.fc34.noarch.rpm
util-linux-2.36.2-1.fc34.x86_64.rpm
vte291-0.64.2-1.fc34.x86_64.rpm
vte-profile-0.64.2-1.fc34.x86_64.rpm
which-2.21-26.fc34.x86_64.rpm
whois-nls-5.5.10-1.fc34.noarch.rpm
xkeyboard-config-2.33-1.fc34.noarch.rpm
xml-common-0.6.3-56.fc34.noarch.rpm
xz-5.2.5-9.fc34.x86_64.rpm
xz-libs-5.2.5-9.fc34.x86_64.rpm
zlib-1.2.11-26.fc34.x86_64.rpm

If there is a need to download a GROUP of packages such as Gnome Desktop, you may do the following

# dnf -y group install "Basic Desktop" GNOME  --installroot=/installroot  --downloadonly --downloaddir=/tmp/repo -releasever=34

*note: If you need to re-download them again on the same system you should make a new /installroot directory.

]]>
259
Remove any potential special characters or spaces from an IP address using AWK https://datastorageguy.com/2023/07/12/remove-any-potential-special-characters-or-spaces-from-an-ip-address-using-awk/ Thu, 13 Jul 2023 00:26:30 +0000 https://datastorageguy.com/?p=249 Got stuck earlier in an interesting regex mystery and I command-line FU'd an AWK Solution.

PROBLEM

I want to strip out all spaces and/or special characters from an IP address

PROCESS

I know how to validate an IP address no problem..


Good IPO

# echo 192.168.1.122 |egrep -q  '[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}'; echo $?
0

Bad IP

# echo 192.168.xxx.111  |egrep -q '[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}'; echo $?
1

However..

What if am gathering user input via script and I want to strip out any and ALL characters except the numeric IP Address!

For example,

If IP

' _192. 168.122.35'_   "

And I want to only display

192.168.122.35

Leading/trailing spaces can be stripped no problem, but it will still print the special characters

# echo "   _192. 168.122.35'_   "|awk '{gsub(/^[[:space:]]+|[[:space:]]+$/,"",$0); print}'
_192. 168.122.35'_
#


SOLUTION

I put together the following awk script to strip out everything and ONLY print the IP address.

awk -F "." '{for (i=1;i<=NF;i++) {sub("[^[:digit:]]+", "", $i);gsub(/^[[:space:]]+|[[:space:]]+$/,"",$i);if (i < NF) {p="."}else{p=""}  ;printf $i p}}'

Example

#  echo ' _ 192 .168 .120.111 "@  '|awk -F "." '{for (i=1;i<=NF;i++) {sub("[^[:digit:]]+", "", $i);gsub(/^[[:space:]]+|[[:space:]]+$/,"",$i);if (i < NF) {p="."}else{p=""}  ;printf $i p}}'
192.168.120.111
#

To put it all together in a quick script called 'btest'

#!/bin/bash
if [ $# != 0 ]; then
        if [ $(echo "$1"  |egrep -q '[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}'; echo $?) == 0 ]; then
                echo "Validated IP address [$1]"
                IP=$(echo "$1"|awk -F "." '{for (i=1;i<=NF;i++) {sub("[^[:digit:]]+", "", $i);gsub(/^[[:space:]]+|[[:space:]]+$/,"",$i);if (i < NF) {p="."}else{p=""}  ;printf $i p}}')
                echo "Corrected IP Address=$IP"
        else
                echo "Invalid IP address [$1]"
        fi

else
        echo "Enter IP address"
fi

If we were to enter an IP address of "192.168.1.11'" which contains a 'tick' at the end , the initial Validation would succeed.

But I can then show you how we use awk to strip out any misc characters

# ./btest "192.168.1.11'"
Validated IP address [192.168.1.11']
Corrected IP Address [192.168.1.11]

If we were to add leading and trailing white spaces on the argument we can see that it is still corrected

# ./btest " 192.168.1.11' "
Validated IP address [ 192.168.1.11' ]
Ensuring IP does not have any special characters or spaces
Corrected IP Address [192.168.1.11]

If we type an invalid IP Address we see it is caught

# ./btest " 192.168.1.xx' "
Invalid IP address [ 192.168.1.xx' ]

If I got extra wild and crazy and used the following for an IP address we would see it would still succeed

# ./btest ' _ 192.168.120.111 "@  '
Validated IP address [ _ 192.168.120.111 "@  ]
Corrected IP Address [192.168.120.111]

Now to put it all together into a script that will gather user input

#!/bin/bash
e=0
while [ $e == 0 ]; do
        printf "Enter IP address > "
        read ip
        if [ ! -z "$ip" ]; then
                if [ $(echo "$ip"  |egrep -q '[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}'; echo $?) == 0 ]; then
                        echo "Validated IP address [$ip]"
                        ip=$(echo "$ip"|awk -F "." '{for (i=1;i<=NF;i++) {sub("[^[:digit:]]+", "", $i);gsub(/^[[:space:]]+|[[:space:]]+$/,"",$i);if (i < NF) {p="."}else{p=""}  ;printf $i p}}')
                        echo "Corrected IP Address [$ip]"
                        e=1
                else
                        echo "Invalid IP address [$ip]"
                        e=0
                fi

        else
                echo "ERROR: Enter IP address"
        fi
done

Example 1

# ./btest
Enter IP address > 192.168.1.222
Validated IP address [192.168.1.222]
Corrected IP Address [192.168.1.222]

Example 2

# ./btest
Enter IP address > '192.168.122.111 '
Validated IP address ['192.168.122.111 ']
Ensuring IP does not have any special characters or spaces
Corrected IP Address [192.168.122.111]
]]>
249
Using AWK to print N lines up until the FIRST MATCH of a string and then exit https://datastorageguy.com/2022/07/01/using-awk-to-print-n-lines-up-until-the-first-match-of-a-string-and-then-exit/ Fri, 01 Jul 2022 16:59:42 +0000 https://datastorageguy.com/?p=185 Often you are looking for a keyword within a log file but you need to print out X lines BEFORE the first match of a string, THEN exit the search.

There are many ways to skin a cat, and here are a few ways.

EXAMPLE 1:

In the following I am looking for 7 lines BEFORE the keyword phrase 'Rolling back'

# cat logfile  | awk   'BEGIN{stopline=7} NR==1,/Rolling back/ {n=NR;l[n]=$0}END{last=n-stopline;for (i=last;i<=n;i++) {print l[i]}}'

Output:

2022-06-11 16:56:26 [pid 39154] LOG-THRIFTCLIENT-0002: [1] [tid 39154] Thrift transport exception type #1 (socket open() error: No route to host); failed to establish connection [addr=tt-peer-controller./port=9090].
Command killed: (signal 14) /usr/tintri/bin/fscmd -a 60 -h 'tt-peer-controller.' get-tuning-variable 'stasisDegradedModeTruncationTimeout'
Can't get 'stasisDegradedModeTruncationTimeout', error 142
Can't get timeouts, error 142
Upgrade completed; exit code 109
2022-06-11T16:57:22.166513-07:00 la-tintri01#b upgrade_pkg[30360]: Script /etc/sysconfig/tintri/post_upd/90-upgrade_fs exit code: 109
2022-06-11T16:57:22.167052-07:00 la-tintri01#b upgrade_pkg[30360]: Can not perform application upgrade, error 109
2022-06-11T16:57:22.167467-07:00 la-tintri01#b upgrade_pkg[30360]: Rolling back, state 9

EXAMPLE 2:

An easier way is to chain with tail; but who in the Linux world wants to do things the easy way right!?!?

#zcat logfile |awk 'NR==1,/Rolling back/' |tail -7

OUTPUT

2022-06-11 16:56:26 [pid 39154] LOG-THRIFTCLIENT-0002: [1] [tid 39154] Thrift transport exception type #1 (socket open() error: No route to host); failed to establish connection [addr=tt-peer-controller./port=9090].
Command killed: (signal 14) /usr/tintri/bin/fscmd -a 60 -h 'tt-peer-controller.' get-tuning-variable 'stasisDegradedModeTruncationTimeout'
Can't get 'stasisDegradedModeTruncationTimeout', error 142
Can't get timeouts, error 142
Upgrade completed; exit code 109
2022-06-11T16:57:22.166513-07:00 la-tintri01#b upgrade_pkg[30360]: Script /etc/sysconfig/tintri/post_upd/90-upgrade_fs exit code: 109
2022-06-11T16:57:22.167052-07:00 la-tintri01#b upgrade_pkg[30360]: Can not perform application upgrade, error 109
2022-06-11T16:57:22.167467-07:00 la-tintri01#b upgrade_pkg[30360]: Rolling back, state 9

EXAMPLE 3

Sometimes we need to search multiple files:

# awk   'NR==1,/Rolling back/' *.log |grep -H -B20 Rolling 

Or for GZ files

# zcat logfile*.gz|awk 'NR==1,/Rolling back/'

OR

# awk 'NR==1,/Rolling back/' <(gzip -dc logfile*.gz)
]]>
185
Telnet to a port on a remote machine without ncat or telnet, or nmap https://datastorageguy.com/2022/05/19/telnet-to-a-port-on-a-remote-machine-without-ncat-or-telnet-or-nmap/ Thu, 19 May 2022 23:59:01 +0000 https://datastorageguy.com/?p=160 There are situations where you may be working on Linux based system, and telnet, ncat or nmap does not exist.

In Linux, you can route a test thru the protocol, destination IP address, and destination  port using the "/dev" linux 'pseudo device' 

The 'telnet' command we are all familiar with is essentially a wrapper for this procedure.

This can be done safely without impact to system operation.

# echo > /dev/tcp/10.10.154.121/10600 && echo "TCP Port 10600 is open"

The same works with UDP

 echo > /dev/udp/10.10.154.121/111 && echo "UDP Port 111 is open"

To test multiple TCP ports via for loop:

# for i in 88 111 135 139 445 464 3268 3269 ; do
echo > /dev/tcp/10.10.154.133/$i && echo "TCP Port $i is open"
done

]]>
160
sed print only line AFTER string match https://datastorageguy.com/2022/05/19/sed-print-only-line-after-string-match/ Thu, 19 May 2022 21:53:40 +0000 https://datastorageguy.com/?p=155 sed -n '/pattern/{n;p;}' infile

File

# cat infile
line 1
line 2
pattern
line 3
line 4

Example

# sed -n '/pattern/{n;p;}' infile
line 3
]]>
155
Remove Leading and Trailing Whitespace using gsub in AWK https://datastorageguy.com/2022/05/19/remove-leading-and-trailing-whitespace-using-gsub-in-awk/ Thu, 19 May 2022 21:50:57 +0000 https://datastorageguy.com/?p=153 # echo " this test "|awk '{gsub(/^[[:space:]]+|[[:space:]]+$/,"",$0); print}' this test ]]> 153 Cut all characters after last match using SED https://datastorageguy.com/2022/05/19/cut-all-characters-after-last-match-using-sed/ Thu, 19 May 2022 21:49:44 +0000 https://datastorageguy.com/?p=151 # echo "xxx/xxxx/xxxxx/yyy" | sed 's|\(.*\)/.*|\1|' # echo "xxxx/x/xx/xx/xxxx/x/yyyyy" | sed 's|\(.*\)/.*|\1|'

Output

xxx/xxxx/xxxxx
xxxx/x/xx/xx/xxxx/x
]]>
151
Increment a variable name within a BASH loop https://datastorageguy.com/2022/05/19/increment-a-variable-name-within-a-bash-loop/ Thu, 19 May 2022 21:47:08 +0000 https://datastorageguy.com/?p=149 #!/bin/bash c=0 for i in a b; do log[$c]="$i" ((c++)) done for i in ${log[@]}; do echo $i done

Example

# ./btest
a
b
]]>
149
Include Line Numbers to bash set-x debug output https://datastorageguy.com/2021/09/06/include-line-numbers-to-bash-set-x-debug-output/ Mon, 06 Sep 2021 19:13:28 +0000 https://datastorageguy.com/?p=116 There are times you need to view the line numbers in a bash script to view script execution.

Within bash 'set -x' either at the shell, or within the bash script will display debug output.

To include line numbers you can use the PS4='${LINENO}:'

The $PS4 variable in Bash is used for the prompt printed before the command line is echoed when the debugging shell option -x is set with the set builtin command

EXAMPLE

#!/bin/bash
PS4='${LINENO}: '
echo "Hello"
echo "World

OUTPUT

# ./test.sh
+ PS4='${LINENO}: '
6: echo Hello
Hello
7: echo World
World
]]>
116