Sunday, September 7, 2025

Service Check

I thought about a simple way of checking if a service is installed and running.  Below is the script for it. 

#!/bin/bash
read -p "Enter service name to check: " ServiceName

# Alternative using grep, uncomment line 5 and comment line 8
#if which "$ServiceName" &>/dev/null; then if ps -aux | grep -v grep | grep -q "$ServiceName"; then echo "$ServiceName is installed and running"; else echo "$ServiceName is installed, but not running"; fi; else echo "$ServiceName is not installed"; fi

# Alternative using pgrep, uncomment line 8 and comment line 5
if which "$ServiceName" &>/dev/null; then if pgrep -c "$ServiceName" > 0; then echo "$ServiceName is installed and running"; else echo "$ServiceName is installed, but not running"; fi; else echo "$ServiceName is not installed"; fi

Feel free to comment if you have a suggestion to make it simpler

Regards,

F. Bobbio C.

 

Monday, July 7, 2025

Certificate Expiration Page

I have wanted to check on expiration dates on certificates on all servers.  I created this bash script and saved it in the same location as the php page below.

#!/bin/bash
currdate=$(date +%s)
printf '%-60s %-29s %15s\n' "Hostname" "Cert. Exp. Date" "Days Remaining"
declare -a StringArray=("aaa" "host1" "host2" "host3" "www")
for val in "${StringArray[@]}"; do
  cert=$(echo | openssl s_client -connect $val.yourdomain.com:443 -servername $val.yourdomain.com 2>/dev/null | openssl x509 -noout -dates | tail -n 1 | cut -d "=" -f 2) && moredays=$(date -d "$cert" +%s)/86400-$currdate/86400 && printf '%-60s %-30s %15s\n' "$val.yourdomain.com" "$cert" "$((moredays)) day(s) remaining"
done
# This section is for servers without the default SSL/TLS port of 443 or IP addresses
cert=$(echo | openssl s_client -connect admanager.yourdomain.com:8444 -servername admanager.yourdomain.com 2>/dev/null | openssl x509 -noout -dates | tail -n 1 | cut -d "=" -f 2) && moredays=$(date -d "$cert" +%s)/86400-$currdate/86400 && printf '%-60s %-30s %15s\n' "adaudit.yourdomain.com" "$cert" "$((moredays)) day(s) remaining"
cert=$(echo | openssl s_client -connect admanager.yourdomain.com:8443 -servername admanager.yourdomain.com 2>/dev/null | openssl x509 -noout -dates | tail -n 1 | cut -d "=" -f 2) && moredays=$(date -d "$cert" +%s)/86400-$currdate/86400 && printf '%-60s %-30s %15s\n' "admanager.yourdomain.com" "$cert" "$((moredays)) day(s) remaining"
cert=$(echo | openssl s_client -connect server1.yourdomain.com:15443 -servername server1.yourdomain.com 2>/dev/null | openssl x509 -noout -dates | tail -n 1 | cut -d "=" -f 2) && moredays=$(date -d "$cert" +%s)/86400-$currdate/86400 && printf '%-60s %-30s %15s\n' "server1.yourdomain.com" "$cert" "$((moredays)) day(s) remaining"
cert=$(echo | openssl s_client -connect unifi.yourdomain.com:8443 -servername unifi.yourdomain.com 2>/dev/null | openssl x509 -noout -dates | tail -n 1 | cut -d "=" -f 2) && moredays=$(date -d "$cert" +%s)/86400-$currdate/86400 && printf '%-60s %-30s %15s\n' "unifi.yourdomain.com" "$cert" "$((moredays)) day(s) remaining"
cert=$(echo | openssl s_client -connect unifi-guest.yourdomain.com:8443 -servername unifi-guest.yourdomain.com 2>/dev/null | openssl x509 -noout -dates | tail -n 1 | cut -d "=" -f 2) && moredays=$(date -d "$cert" +%s)/86400-$currdate/86400 && printf '%-60s %-30s %15s\n' "unifi-guest.yourdomain.com" "$cert" "$((moredays)) day(s) remaining"
cert=$(echo | openssl s_client -connect 1.2.3.4:443 -servername 1.2.3.4 2>/dev/null | openssl x509 -noout -dates | tail -n 1 | cut -d "=" -f 2) && moredays=$(date -d "$cert" +%s)/86400-$currdate/86400 && printf '%-60s %-30s %15s\n' "server2.yourdomain.com" "$cert" "$((moredays)) day(s) remaining"
cert=$(echo | openssl s_client -connect 5.6.7.8:443 -servername 5.6.7.8 2>/dev/null | openssl x509 -noout -dates | tail -n 1 | cut -d "=" -f 2) && moredays=$(date -d "$cert" +%s)/86400-$currdate/86400 && printf '%-60s %-30s %15s\n' "server3.yourdomain.com" "$cert" "$((moredays)) day(s) remaining"

The output was similar to this:

Hostname                                                     Cert. Exp. Date                Days Remaining
www.microsoft.com                                            Aug 21 16:01:06 2025 GMT       45 day(s) remaining
www.amazon.com                                               Jun 29 23:59:59 2026 GMT       357 day(s) remaining

In case you only want to check the certificate on one host, the following script can be used.

#!/bin/bash
read -p "Enter Fully Qualified Domain Name (FQDN) (i.e.: www.yourdomain.com): " hostcheck
read -p "Enter port number to check or hit Enter for default port of 443: " portnum
portnum="${portnum:-443}"
printf '%-60s %-29s %15s\n' "Hostname" "Cert. Exp. Date" "Days Remaining"
cert=$(echo | openssl s_client -connect $hostcheck:$portnum -servername hostcheck 2>/dev/null | openssl x509 -noout -dates | tail -n 1 | cut -d "=" -f 2) && moredays=$(date -d "$cert" +%s)/86400-$(date +%s)/86400 && printf '%-60s %-30s %15s\n' "$hostcheck" "$cert" "$((moredays)) day(s) remaining"

Finally, display it via a php page with this code

<head>
  <title>Certs Check</title>
  <link rel="icon" type="image/ico" href="Company.ico">
</head>
<?php
  $URL1=$_SERVER['REQUEST_URI'];
  header("Refresh: 900; URL=$URL1");
  $Output = shell_exec('/var/cache/www/html/Certs.sh');
  echo "<pre>$Output</pre>";
?>

Change /var/cache/www/html/Certs.sh to the path and name of your shell script.

Feel free to comment if you have a suggestion to make it simpler

Regards,

F. Bobbio C.

 

Monday, August 5, 2024

Slackware64-current Kernel 6.10.3 EVDI-Kernel

Update 08-23-2024:  Version 1.14.6 of evdi (https://github.com/DisplayLink/evdi/releases/tag/v1.14.6) introduced support for  the 6.10 kernel and preliminary support for the 6.11 kernel.

I use a Dell USB 3.0 docking station for multiple monitors, which uses a DisplayLink chipset.  After the latest kernel upgrade to 6.10.3, evdi-kernel did not want to repackage, due to missing module/evdi.ko and would not proceed.  Once I copied evdi.ko, evdi 1.14.5 did repackage and installed, but it could not load the evdi module.  I took a look at evdi 1.14.4 which would not repackage either and found that it was due to module/evdi_gem.c so I copied evdi_gem.c from 1.14.5 into 1.14.4 and repackaged and installed 1.14.4 successfully.  Once I rebooted, I could use my dual monitors again

Regards,

F. Bobbio C.

Saturday, September 9, 2023

Check Open Files By Process Name

I was tasked with finding how many files were open for a specific process name.  The process name had many process IDs (PIDs) running, which could be listed using the following command:

    ps -eaf | grep -i<ProcessName>

The PIDs were listed in the second column, which the required the addition of one more command:

    ps -eaf | grep -i $CheckProcessName | awk -F ' ' '{print $2}'

The output was a list of PIDs, in one column, and the amount of open files could be checked for each of them, by running the following command for the PIDs:

    lsof -p <PID1>,<PID2>,<PID3>,...,<PIDn> | wc -l

This was cumbersome for processes that have multiple PIDs, thus adding one extra command to list all PIDs in one line:

    ps -eaf | grep -i $CheckProcessName | awk -F ' ' '{print $2}' | tr '\n' ,

 I decided to combine it all together and came up with this one-liner:

    lsof -p $(ps -eaf | grep -i <ProcessName> | awk -F ' ' '{print $2}' | tr '\n' ,) | wc -l

Last, but not least, I created a shell script that could be used to check on any process:

    #!/bin/bash
    read -p "Enter process name: " CheckProcessName
    lsof -p $(ps -eaf | grep -i $CheckProcessName | awk -F ' ' '{print $2}' | tr '\n' ,) | wc -l

Feel free to comment if you have a suggestion to make it simpler

Regards,

F. Bobbio C.

Monday, October 31, 2022

Dynect Zones + Record_Id Export

 I was tasked with exporting all records from Dynect to import into another portal.  There was some information here:  https://support.globaldots.com/hc/en-us/articles/115004002829-Dyn-How-to-get-all-records-from-a-zone-through-the-API  which requires the creation of a file in json format with these parameters { "customer_name" : "ACME" , "user_name" : "user", "password" : "secretpassword" }

This would allow me to export only partial information and I needed to export over 750 zones, with over 100 records per zone in some cases.  I created the following script, which exports each domain in the zones into its own json file

# Based on https://help.dyn.com/rest-resources/
#!/bin/bash
Token=$(curl -sX POST -d @Credentials.txt -H "Content-Type: application/json" https://api.dynect.net/REST/Session/ | awk -F '"' '{print $10}')
curl -sX GET -H "Content-Type: application/json" -H "Auth-Token: $Token" https://api.dynect.net/REST/Zone/ >> Zones.json
cat Zones.json | awk -F ']' '{print $1}' | awk -F '[' '{print $2}' > Zones.json.1
sed -i -e 's|/||g' -i -e 's|RESTZone||g' -i -e 's|,||g' -i -e 's|"||g' Zones.json.1
rm Zones.json && mv Zones.json.1 Zones.json
AllZones=$(cat Zones.json)
for val in ${AllZones[@]};do
  curl -sX GET -H "Content-Type: application/json" -H "Auth-Token: $Token" https://api.dynect.net/REST/AllRecord/$val/ >> $val.json
  echo -e Exporting data for zone $val
  cat $val.json | awk -F ']' '{print $1}' | awk -F '[' '{print $2}' > $val.json.1
  sed -i -e 's|,||g' -i -e 's|"||g' $val.json.1
  rm $val.json && mv $val.json.1 $val.json
done
for i in $(cat Zones.json);do
  EachZone=$(cat $i.json)
  for val in ${EachZone[@]};do
    EachZoneName=$(echo $val | awk -F '/' '{print $4}')
    ZoneNameAttribute=$(echo $val | awk -F '/' '{print $3}')
    curl -sX GET -H "Content-Type: application/json" -H "Auth-Token: $Token" https://api.dynect.net$val/ >> $EachZoneName-Detailed.json && echo >> $EachZoneName-Detailed.json && echo >> $EachZoneName-Detailed.json
    echo -e Exporting detailed data for $ZoneNameAttribute in zone $EachZoneName
    cat $i-Detailed.json | awk -F 'zone": ' '{print $2}' | awk -F ', "record_id":' '{print $1}' >> $i-Detailed-Cleaned.json
    sed -i -e 's|,|\n|g' -i -e 's|"||g' $i-Detailed-Cleaned.json
  done
done
#rm *-Detailed.json

Regards,

F. Bobbio C.

Sunday, August 28, 2022

1Password In Slackware64-current

There is currently no SlackBuild for 1password.  It can be installed using the rpm file, via the following script:

#!/bin/bash
rm 1password-latest.rpm 1password-latest.txz
wget https://downloads.1password.com/linux/rpm/beta/x86_64/1password-latest.rpm
sudo rpm2txz 1password-latest.rpm
sudo killall 1password
sudo removepkg 1password-latest
sudo installpkg 1password-latest.txz
sudo cp custom_allowed_browsers /opt/1Password/resources/

Copy custom_allowed_browsers from /opt/1Password/resources/ and modify it by adding a line with the default browser in use, such as firefox

Regards,

F. Bobbio C.

Monday, April 5, 2021

Slackware64-current Query Installed Packages Versions

Update 08-28-2022: I added more packages to be queried.  The script is now hosted in GitLab and has one extra line comparing the versions of the packages.

Original:

I needed a script to check on the current versions of  specific packages, as well as the latest versions from the vendors or manufacturer websites.  I used the github and gitlab repositories for the packages, along with awk to query the versions and tr to remove the v in front of the version numbers.  I even added a line for Microsoft Teams.

First attempt:

#!/usr/bin/bash
echo DKMS && echo Current:  && ls /var/log/packages | grep dkms | awk -F "-" '{print $2}' && echo Latest: && git ls-remote --tags --refs --sort="version:refname" git://github.com/dell/dkms | awk -F/ 'END{print$NF}' | tr -d \v
echo
echo EVDI: && echo Current:  && ls /var/log/packages | grep evdi-1 | awk -F "-" '{print $2}' && echo Latest: && git ls-remote --tags --refs --sort="version:refname" git://github.com/DisplayLink/evdi | awk -F/ 'END{print$NF}' | tr -d \v
echo
echo FreeRDP && echo Current: && xfreerdp /version | awk '{print $5}' && echo "Latest:" && git ls-remote --tags --refs --sort="version:refname" git://github.com/FreeRDP/FreeRDP | awk -F/ 'END{print$NF}' | tr -d \v
echo
echo NVIDIA: && echo Current: && grep "X Driver" /var/log/Xorg.0.log | awk '{print $8}' && echo Latest: && git ls-remote --tags --refs --sort="version:refname" git://github.com/NVIDIA/nvidia-xconfig | awk -F/ 'END{print$NF}' | tr -d \v
echo
echo Remmina: && echo Current: && ls /var/log/packages | grep Remmina | awk -F "-" '{print $2}' | tr -d \v && echo Latest: && git ls-remote --tags --refs --sort="version:refname" https://gitlab.com/Remmina/Remmina.git | awk -F/ 'END{print$NF}' | tr -d \v
echo
echo Teams: && echo Current: && ls /var/log/packages | grep teams-insiders | awk -F "-" '{print $3}' | tr -d \v && echo Latest: && curl -s https://packages.microsoft.com/repos/ms-teams/pool/main/t/teams-insiders/ | awk -F "teams" 'NF > 1 {print $NF}' | tail -1 | awk -F "_" '{print $2}'

Second attempt:

#!/usr/bin/bash
CurrentDKMS=$(ls /var/log/packages | grep dkms | awk -F "-" '{print $2}' 2>&1)
LatestDKMS=$(git ls-remote --tags --refs --sort="version:refname" git://github.com/dell/dkms | awk -F/ 'END{print$NF}' | tr -d \v 2>&1)
echo DKMS Current: $CurrentDKMS Latest: $LatestDKMS
CurrentEVDI=$(ls /var/log/packages | grep evdi-1 | awk -F "-" '{print $2}' 2>&1)
LatestEVDI=$(git ls-remote --tags --refs --sort="version:refname" git://github.com/DisplayLink/evdi | awk -F/ 'END{print$NF}' | tr -d \v 2>&1)
echo EVDI Current: $CurrentEVDI Latest: $LatestEVDI
CurrentFreeRDP=$(xfreerdp /version | awk '{print $5}' 2>&1)
LatestFreeRDP=$(git ls-remote --tags --refs --sort="version:refname" git://github.com/FreeRDP/FreeRDP | awk -F/ 'END{print$NF}' | tr -d \v 2>&1)
echo FreeRDP Current: $CurrentFreeRDP Latest: $LatestFreeRDP
CurrentNVIDIA=$(grep "X Driver" /var/log/Xorg.0.log | awk '{print $8}' 2>&1)
LatestNVIDIA=$(git ls-remote --tags --refs --sort="version:refname" git://github.com/NVIDIA/nvidia-xconfig | awk -F/ 'END{print$NF}' | tr -d \v 2>&1)
echo NVIDIA Current: $CurrentNVIDIA Latest: $LatestNVIDIA
CurrentRemmina=$(ls /var/log/packages | grep Remmina | awk -F "-" '{print $2}' | tr -d \v 2>&1)
LatestRemmina=$(git ls-remote --tags --refs --sort="version:refname" https://gitlab.com/Remmina/Remmina.git | awk -F/ 'END{print$NF}' | tr -d \v 2>&1)
echo Remmina Current: $CurrentRemmina Latest: $LatestRemmina
CurrentTeams=$(ls /var/log/packages | grep teams-insiders | awk -F "-" '{print $3}' | tr -d \v 2>&1)
LatestTeams=$(curl -s https://packages.microsoft.com/repos/ms-teams/pool/main/t/teams-insiders/ | awk -F "_" 'NF >1 {print $2}' | tail -1 2>&1)
echo Teams Current: $CurrentTeams Latest: $LatestTeams

Regards,

F. Bobbio C.