Tag: Crontab

  • Unix – Crontab

    #! /bin/sh
    # Usage : ./crontabintf

     1: set -f
     2: choice=0
     3: while [ 0 ]
     4: do
     5:  
     6: echo "1.Display crontab jobs."
     7:  
     8: echo "2.Insert a job."
     9:  
     10: echo "3.Remove a job."
     11:  
     12: echo "4.Exit."
     13:  
     14: echo -n "Select>"
     15:  
     16: read choice
     17:  
     18: case $choice in
     19:  
     20: 1) line=1
     21:  
     22: crontab -l > $HOME/.jobs
     23:  
     24: res="`wc -l $HOME/.jobs`"
     25:  
     26: set - $res;lines=$1;
     27:  
     28: while [ $line -le $lines ]
     29:  
     30: do
     31:  
     32: res="`head -$line $HOME/.jobs | tail -1`"
     33:  
     34: set - $res;disp=" ";
     35:  
     36: for arg
     37:  
     38: do
     39:  
     40: if [ "$arg" = '*' ]
     41:  
     42: then
     43:  
     44: disp="$disp Any"
     45:  
     46: else
     47:  
     48: disp="$disp $arg"
     49:  
     50: fi
     51:  
     52: done
     53:  
     54: set - $disp
     55:  
     56: echo "JOB $line-->"
     57:  
     58: echo "minute: $1";shift;
     59:  
     60: echo "Hour: $1";shift;
     61:  
     62: echo "Date: $1/$2";shift;shift;
     63:  
     64: echo "Day of week: $1";shift;
     65:  
     66: echo "Command:$*"
     67:  
     68: line=`expr $line + 1`
     69:  
     70: done;;
     71:  
     72: 2) crontab -l >$HOME/.newjobs
     73:  
     74: selection=0
     75:  
     76: minutes="any"
     77:  
     78: hours="any"
     79:  
     80: monthday="any"
     81:  
     82: month="any"
     83:  
     84: weekday="any"
     85:  
     86: while [ $selection -ne 7 ]
     87:  
     88: do
     89:  
     90: echo "1.Set the command(-obligatory):"
     91:  
     92: echo "Set periodicity of command."
     93:  
     94: echo "2.Set minutes:0-59"
     95:  
     96: echo "3.Set hours:0-23"
     97:  
     98: echo "4.Set day of month:1-31"
     99:  
     100: echo "5.Set month:1-12"
     101:  
     102: echo "6.Set day of week:Mon-Sun"
     103:  
     104: echo "7.Ready."
     105:  
     106: echo -n "Enter>"
     107:  
     108: read selection
     109:  
     110: case $selection in
     111:  
     112: 1)echo -n "Enter>"
     113:  
     114: read command;;
     115:  
     116: 2) echo -n "If more than one choice,seperate by comma..Enter>"
     117:  
     118: read minutes;;
     119:  
     120: 3) echo -n "If more than one choice,seperate by comma..Enter>"
     121:  
     122: read hours;;
     123:  
     124: 4) echo -n "If more than one choice,seperate by comma..Enter>"
     125:  
     126: read monthday;;
     127:  
     128: 5) echo -n "If more than one choice,seperate by comma..Enter>"
     129:  
     130: read month;;
     131:  
     132: 6) echo -n "If more than one choice,seperate by comma..Enter>"
     133:  
     134: read weekday;;
     135:  
     136: 7) break;;
     137:  
     138: *) continue;;
     139:  
     140: esac
     141:  
     142: done
     143:  
     144: periodicity=" "
     145:  
     146: for inst in $minutes $hours $monthday $month $weekday
     147:  
     148: do
     149:  
     150: if [ "$inst" = "any" ]
     151:  
     152: then
     153:  
     154: periodicity="$periodicity *"
     155:  
     156: else
     157:  
     158: periodicity="$periodicity $inst"
     159:  
     160: fi
     161:  
     162: done
     163:  
     164: echo "$periodicity $command">>$HOME/.newjobs
     165:  
     166: crontab $HOME/.newjobs;;
     167:  
     168: 3) crontab -l >$HOME/.jobs
     169:  
     170: echo "Job to remove"
     171:  
     172: echo -n "Enter Job's number as listed above>"
     173:  
     174: read jobnmb
     175:  
     176: res="`wc -l $HOME/.jobs`"
     177:  
     178: set - $res;
     179:  
     180: rest=`expr $1 - $jobnmb`
     181:  
     182: jobnmb=`expr $jobnmb - 1`
     183:  
     184: head -$jobnmb $HOME/.jobs | cat >$HOME/.njobs
     185:  
     186: tail -$rest $HOME/.jobs | cat >>$HOME/.njobs
     187:  
     188: crontab $HOME/.njobs;;
     189:  
     190: 4) rm $HOME/.jobs $HOME/.newjobs
     191:  
     192: exit;;
     193:  
     194: *) continue;;
     195:  
     196: esac
     197:  
     198: done