#### without command

if ! ps -ef | grep -v grep | grep "ssh -fN -L [allow]:port:target:port username@address" > /dev/null
then
    nohup ssh -fN -L [allow]:port:target:port username@address >> ~/.crontab/sshforward.out 2>&1 &
fi

if ! ps -ef | grep -v grep | grep "ssh -fN -R [allow]:port:target:port username@address" > /dev/null
then
    nohup ssh -fN -R [allow]:port:target:port username@address >> ~/.crontab/sshforward.out 2>&1 &
fi

if ! ps -ef | grep -v grep | grep "ssh -fN -D [allow]:port username@address" > /dev/null
then
    nohup ssh -fN -D [allow]:port username@address >> ~/.crontab/sshforward.out 2>&1 &
fi

#### with command

if ! ps -ef | grep -v grep | grep "ssh -f -L [allow]:port:target:port username@address" > /dev/null
then
    nohup ssh -f -L [allow]:port:target:port username@address 'command; source sshstart.sh [uid]; sleep infinity' >> ~/.crontab/sshforward.out 2>&1 &
fi

if ! ps -ef | grep -v grep | grep "ssh -f -R [allow]:port:target:port username@address" > /dev/null
then
    nohup ssh -f -R [allow]:port:target:port username@address 'command; source sshstart.sh [uid]; sleep infinity' >> ~/.crontab/sshforward.out 2>&1 &
fi

if ! ps -ef | grep -v grep | grep "ssh -f -D [allow]:port username@address" > /dev/null
then
    nohup ssh -f -D [allow]:port username@address 'command; source sshstart.sh [uid]; sleep infinity' >> ~/.crontab/sshforward.out 2>&1 &
fi