ICT: Diary
D: 28 W: 05
| < | May 2020 | > | ||||
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 | ||||||
[ < ]
Sunday, 31 May 2020 [ >
]
sshlink
I have script that I use to ensure that I can access my home network on OpenBSD the script is:
#! /bin/sh
GREPSSH=$(ps ax|grep [l]inkkey|awk -F ' ' '{print $1}')
if [ "$GREPSSH" -eq NULL ]
then
echo "no sshlink \n"
/usr/bin/ssh -nNT -i ~/.ssh/linkkey -R 22222:localhost:22 \
-o ServerAliveInterval=60 \
-o ExitOnForwardFailure=yes user@server.crowsons.com &
else echo $GREPSSH
exit 1
fi
Converting bash to run on linux systems the script would fail, silently, adding Unofficial BASH Srict Mode, did not shed any light on the error - splitting it down on the CLI, tracked the error down to:
user@pizero:~ $ ps ax | grep [l]inkkey | awk -f ' ' '{print $1}'
awk: cannot open (No such file or directory)
the grep was generating two spaces in the output so the script was fixed by the removal of grep, and using awk's regex:
#! /bin/bash
set -euo pipefail
IFS=$'\n\t'
GREPSSH=$( ps ax | awk '/[l]inkkey/ {print $1}' )
if [ -z ${GREPSSH} ]
then
echo "no ssh link \n"
/usr/bin/ssh -nNT -i ~/.ssh/linkkey -R 22222:localhost:22 \
-o ServerAliveInterval=60 \
-o ExitOnForwardFailure=yes user@server.crowsons.com &
else echo ${GREPSSH}
exit 1
fi
The GREPSSH=$(ps ax | awk '/linkkey/ {print $1}') improved my sh script on OpenBSD boxen.
$Id: dates.htm,v 1
$Id: diary,v 1.38 2025/01/01 22:43:54 fred Exp $