[script] 利用 sed 指令, 啟動或停用 crontab 裡的特定項目

用來關閉某個項目的 script

#!/bin/bash
####  列出目前的 crontab
path="/home/joechen/test"
crontab -l > "$path"/crontab.current

####  替換現有規則
if [ -z "$1" ]; then
  echo "key-patten or program-name is not set."
else
  #patten="$1"
  sed -e 's/.*'$1'/#&/' "$path"/crontab.current > "$path"/crontab.new
  crontab "$path"/crontab.new
fi

用來開啟某個項目的 script

#!/bin/bash
####  列出目前的 crontab
path="/home/joechen/test"
crontab -l > "$path"/crontab.current

####  替換現有規則
if [ -z "$1" ]; then
  echo "key-patten or program-name is not set."
else
  sed -e '/'$1'/s/^#//' "$path"/crontab.current > "$path"/crontab.new
  crontab "$path"/crontab.new
fi

Leave a comment

Your comment


Warning: Undefined variable $user_ID in /var/www/sites/wordpress/wp-content/themes/librio/comments.php on line 67