#!/bin/bash pid=$(ps aux | grep -E '[0-9] (/usr/bin/)?node app.js' | while read user pid rest; do echo $pid; done) if [[ "$pid" != "" ]]; then echo "Killing ${pid}" kill $pid else echo "No node server found" fi