ICT: Diary
D: 28 W: 05

< May 2020 >
Sun Mon Tue Wed Thu Fri Sat
 12
3456789
10111213141516
17181920212223
24252627282930
31 

Based on notaweblog.php by joshua stein

[ ] 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.

bashawkpipefail


$Id: diary,v 1.38 2025/01/01 22:43:54 fred Exp $