#!/bin/sh

my_hour=$(date +"%H")
my_min=$(date +"%M")
# my_month=$(date +"%m")
# my_year=$(date +"%Y")
# my_day=$(date +"%d")
my_min=$((my_min+2))
my_hour=$((my_hour))
my_cmd="/bin/bash /mnt/user/scripts/inotify-command/scanned.sh"
#my_cmd="touch /tmp/testdenis"
my_crontab="/crontab/root"
cron_temp="/tmp/crontemp"
cron_new="/tmp/cronnew"
job_pattern="scanned.sh"

#-----------------------------------------------------------------------------
#Min    Hour    Day     Month   Weekday Command
#-----------------------------------------------------------------------------
#crontab -l /crontab/root | { cat; echo "$my_min $my_hour * * * $my_cmd ; crontab -l /crontab/root | grep -v scanner.sh | crontab /crontab/root"; } | crontab - /crontab/root

#crontab -l | { cat; echo "$my_min $my_hour * * * $my_cmd ; crontab -l | grep -v $job_pattern | crontab -"; } | crontab -

#touch $my_crontab
#/usr/bin/crontab $my_crontab
echo "$my_min $my_hour * * * $my_cmd" >> $my_crontab
/usr/bin/crontab $my_crontab

sleep 180

cat $my_crontab > /tmp/crontemp
awk '$0!~/scanned.sh/ { print $0 }' $cron_temp >$cron_new
cp $cron_new $my_crontab
/usr/bin/crontab $my_crontab

#crontab -l > /tmp/crontemp
#rm $my_crontab
# /usr/bin/crontab $my_crontab -l | grep -v 'scanner.sh'  | /usr/bin/crontab $my_crontab -