#!/bin/bash line="0,15,30,45 * * * * $HOME/bin/touch-connserv" tempfile=/tmp/touch-connserv.temp.$$ # The 0 makes $tempfile get removed on script graceful exit trap "rm -f $tempfile" $(seq 0 15) crontab -l > "$tempfile" if fgrep -qx "$line" "$tempfile" then exit 0 else echo "$line" >> "$tempfile" # This replaces the crontab with $tempfile crontab "$tempfile" exit 0 fi