ICT: Diary
D: 193 W: 28

< 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:
#! /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: dates.htm,v 1.1375 2020/07/08 23:38:09 fred Exp $

$Id: diary,v 1.27 2017/09/01 17:12:44 fred Exp $