Friday 17 April 2015

Bind Assertion in SystemVerilog

When RTL is already written and it becomes responsibility of a verification engineer to add assertion. And RTL designer does not want verification engineer to modify his RTL for the sake of adding assertion then, bind feature of SystemVerilog comes for rescue.
One can write all the assertion he or she wants to write in a separate file and using bind, he or she can bind the ports of his assertion file with the port/signals of the RTL in his test-bench code. What a cool feature.

The bind directive can be specified in any of the following:
  • A module
  • An interface
  • A compilation-unit scope

There are three forms of bind syntax.
  1. Binding is done to ALL instances of a module.
  2. Binding is done to single instance of a module.
  3. Binding is done to list of (multiple) instance of a module.

//=================================================
// Actual DUT RTL
//=================================================

module dut (
            input  wire clk,
            input  wire req,
            input  wire reset,
            output reg  gnt
           );
  always @ (posedge clk)
  begin
    gnt <= req;
  end
endmodule : dut
//=================================================

//=================================================
// Assertion Module
//=================================================

module assertion_module(
                        input wire clk_ip,
                        input wire req_ip,
                        input wire reset_ip,
                        input wire gnt_ip
                       );
  //=================================================
  // Sequence Layer
  //=================================================

  sequence req_gnt_seq;
    (~req_ip & gnt_ip) ##1 (~req_ip & ~gnt_ip);
  endsequence
  //=================================================
  // Property Specification Layer
  //=================================================

  property req_gnt_prop;
    @ (posedge clk_ip)
      disable iff (reset_ip)
        req_ip |=> req_gnt_seq;
  endproperty
  //=================================================
  // Assertion Directive Layer
  //=================================================

  req_gnt_assert : assert property (req_gnt_prop)
                   else
                   begin
                     $display("@%0dns Assertion Failed", $time);
                   end
endmodule : assertion_module
//=================================================


//=================================================
// Bind Module
//=================================================

module binding_module();
//=================================================
// Bind by Module name : This will bind ALL instance of DUT
//=================================================

// Syntax:
//   bind   RTL_Module_Name   Assertion_module_Name   Instance_Name


  bind dut assertion_module U_assert_ip (
                                         .clk_ip   (clk),
                                         .req_ip   (req),
                                         .reset_ip (reset),
                                         .gnt_ip   (gnt)
                                        );


//=================================================
// Bind by instance name : This will bind only one particular instance of DUT
//=================================================

// Syntax:
//   bind   RTL_Module_Name   :Instance_Path   Assertion_module_Name   Instance_Name


//  bind dut :$root.bind_assertion_tb.DUT_INST_1 assertion_module U_assert_ip (
//                                                                             .clk_ip   (clk),
//                                                                             .req_ip   (req),
//                                                                             .reset_ip (reset),
//                                                                             .gnt_ip   (gnt)
//                                                                            );


//=================================================
// Bind by instance name list : This will bind multiple instances of DUT
//=================================================

// Syntax:
//   bind   RTL_Module_Name   :Instance1_Path, Instance2_Path   Assertion_module_Name   Instance_Name

//  bind dut :$root.bind_assertion_tb.DUT_INST_1, $root.bind_assertion_tb.DUT_INST_2 assertion_module U_assert_ip (
//                                             .clk_ip   (clk),
//                                             .req_ip   (req),
//                                             .reset_ip (reset),
//                                             .gnt_ip   (gnt)
//                                           );


//=================================================
endmodule : binding_module


//=================================================
// TEST Module
//=================================================

module bind_assertion_tb();

  reg clk = 0;
  reg reset, req = 0;
  wire gnt;
 
  always #3 clk ++;
 
  initial begin
    reset <= 1;
    #20 reset <= 0;

    // Make the assertion pass

    #100 @ (posedge clk) req  <= 1;
    @ (posedge clk) req <= 0;

    // Make the assertion fail
    #100 @ (posedge clk) req  <= 1;
    repeat (5) @ (posedge clk);
    req <= 0;

    #10 $finish;
  end
 
  dut DUT_INST_1 (clk,req,reset,gnt);
  dut DUT_INST_2 (clk,req,reset,gnt);
  dut DUT_INST_3 (clk,req,reset,gnt);
 
endmodule : bind_assertion_tb



//=================================================
//Output:  Bind by Module name : This will bind ALL instance of DUT
//=================================================

//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_1.U_assert_ip.req_gnt_assert: started at 237s failed at 243s
//        Offending '((~req_ip) & gnt_ip)'
//@243ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_2.U_assert_ip.req_gnt_assert: started at 237s failed at 243s
//        Offending '((~req_ip) & gnt_ip)'
//@243ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_3.U_assert_ip.req_gnt_assert: started at 237s failed at 243s
//        Offending '((~req_ip) & gnt_ip)'
//@243ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_1.U_assert_ip.req_gnt_assert: started at 243s failed at 249s
//        Offending '((~req_ip) & gnt_ip)'
//@249ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_2.U_assert_ip.req_gnt_assert: started at 243s failed at 249s
//        Offending '((~req_ip) & gnt_ip)'
//@249ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_3.U_assert_ip.req_gnt_assert: started at 243s failed at 249s
//        Offending '((~req_ip) & gnt_ip)'
//@249ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_1.U_assert_ip.req_gnt_assert: started at 249s failed at 255s
//        Offending '((~req_ip) & gnt_ip)'
//@255ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_2.U_assert_ip.req_gnt_assert: started at 249s failed at 255s
//        Offending '((~req_ip) & gnt_ip)'
//@255ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_3.U_assert_ip.req_gnt_assert: started at 249s failed at 255s
//        Offending '((~req_ip) & gnt_ip)'
//@255ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_1.U_assert_ip.req_gnt_assert: started at 255s failed at 261s
//        Offending '((~req_ip) & gnt_ip)'
//@261ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_2.U_assert_ip.req_gnt_assert: started at 255s failed at 261s
//        Offending '((~req_ip) & gnt_ip)'
//@261ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_3.U_assert_ip.req_gnt_assert: started at 255s failed at 261s
//        Offending '((~req_ip) & gnt_ip)'



//=================================================
//Output: Bind by instance name : This will bind only one particular instance of DUT
//=================================================

//"bind_top.sv", 43: bind_assertion_tb.DUT_INST.U_assert_ip.req_gnt_assert: started at 237s failed at 243s
//        Offending '((~req_ip) & gnt_ip)'
//@243ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST.U_assert_ip.req_gnt_assert: started at 243s failed at 249s
//        Offending '((~req_ip) & gnt_ip)'
//@249ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST.U_assert_ip.req_gnt_assert: started at 249s failed at 255s
//        Offending '((~req_ip) & gnt_ip)'
//@255ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST.U_assert_ip.req_gnt_assert: started at 255s failed at 261s
//        Offending '((~req_ip) & gnt_ip)'
//@261ns Assertion Failed



//=================================================
//Output: Bind by instance name list : This will bind multiple instances of DUT
//=================================================

//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_1.U_assert_ip.req_gnt_assert: started at 237s failed at 243s
//        Offending '((~req_ip) & gnt_ip)'
//@243ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_2.U_assert_ip.req_gnt_assert: started at 237s failed at 243s
//        Offending '((~req_ip) & gnt_ip)'
//@243ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_1.U_assert_ip.req_gnt_assert: started at 243s failed at 249s
//        Offending '((~req_ip) & gnt_ip)'
//@249ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_2.U_assert_ip.req_gnt_assert: started at 243s failed at 249s
//        Offending '((~req_ip) & gnt_ip)'
//@249ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_1.U_assert_ip.req_gnt_assert: started at 249s failed at 255s
//        Offending '((~req_ip) & gnt_ip)'
//@255ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_2.U_assert_ip.req_gnt_assert: started at 249s failed at 255s
//        Offending '((~req_ip) & gnt_ip)'
//@255ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_1.U_assert_ip.req_gnt_assert: started at 255s failed at 261s
//        Offending '((~req_ip) & gnt_ip)'
//@261ns Assertion Failed
//"bind_top.sv", 43: bind_assertion_tb.DUT_INST_2.U_assert_ip.req_gnt_assert: started at 255s failed at 261s
//        Offending '((~req_ip) & gnt_ip)'
//@261ns Assertion Failed



 

Thursday 16 April 2015

Pass unpack array between two modules

module module1();
  bit dyn_ary[11];
  initial begin
    foreach (dyn_ary[i]) begin
      dyn_ary[i] = $urandom_range(10, 12323);
    end
 
    #40;
    foreach (dyn_ary[i]) begin
      $display ($time,,"module1 : dyn_ary[%0d]=%0h", i, dyn_ary[i]);
    end
  end
endmodule : module1


module module2 (input bit dyn_array[11]);
  initial begin
    #100;
    foreach (dyn_array[i]) begin
      $display($time,,"module2 : dyn_array[%0d]=%0h", i, dyn_array[i]);
    end
  end
endmodule : module2
 

module top_module();
  module1 M1 ();
  module2 M2 (.dyn_array(M1.dyn_ary));
endmodule : top_module


Output:
 40 module1 : dyn_ary[0]=0
 40 module1 : dyn_ary[1]=0
 40 module1 : dyn_ary[2]=1
 40 module1 : dyn_ary[3]=0
 40 module1 : dyn_ary[4]=1
 40 module1 : dyn_ary[5]=1
 40 module1 : dyn_ary[6]=0
 40 module1 : dyn_ary[7]=1
 40 module1 : dyn_ary[8]=0
 40 module1 : dyn_ary[9]=1
 40 module1 : dyn_ary[10]=1
100 module2 : dyn_array[0]=0
100 module2 : dyn_array[1]=0
100 module2 : dyn_array[2]=1
100 module2 : dyn_array[3]=0
100 module2 : dyn_array[4]=1
100 module2 : dyn_array[5]=1
100 module2 : dyn_array[6]=0
100 module2 : dyn_array[7]=1
100 module2 : dyn_array[8]=0
100 module2 : dyn_array[9]=1
100 module2 : dyn_array[10]=1

Strength comparision in Systemverilog

`define compSigValues(sig_a, sig_b)\
  begin\
  string sig_a_strength, sig_b_strength;\
  sig_a_strength = $sformatf("%v", sig_a);\
  sig_b_strength = $sformatf("%v", sig_b);\
  if ( sig_a_strength == sig_b_strength) begin\
    $display("Signal values %s and %s match", sig_a_strength, sig_b_strength);\
  end\
  else begin\
    $display("Signal values %s and %s don't match", sig_a_strength, sig_b_strength);\
  end\
 end

module top ();
  wire a, b;
  wire c, d;

  assign (strong1, strong0) a = 1;
  assign (pull1, pull0)     b = 1;
  assign (weak1, weak0)     c = 1;
  assign (weak1, weak0)     d = 1;

  initial begin
    #5;
    $display("comparision of a, b");
    `compSigValues(a, b)

    $display("comparision of c, d");
    `compSigValues(c, d)
  end
endmodule

 
Output:
comparision of a, b
Signal values St1 and Pu1 don't match
comparision of c, d
Signal values We1 and We1 match

Constraint Override in Systemverilog

Same variable is constrained in base as well as child (extended) class but constraint name is same in both base  (constraint_cn) and child (constraint_cn) class.

class base;
  rand int unsigned data;
  constraint constraint_cn
  {
    data inside {[1:100]};
  }
endclass : base

class child extends base;
  constraint constraint_cn
  {
    data inside {[101:200]};
  }
endclass : child

module top();
  child C;
  initial begin
    C = new();
    if (!C.randomize()) begin
      $display("Randomization failed");
    end
    else begin
      $display("data = %0d", C.data);
    end
  end
endmodule : top

Output:
data = 114

Tool will try to solve only child (extended) class's constraint because Child class Override base class's Constraint as both constraint is having same name.

Take another example.


Same variable is constrained in base as well as child (extended) class but constraint name is different in base (constraint_cn) and child (constraint_cn_c) class.

class base;
  rand int unsigned data;
  constraint constraint_cn
  {
    data inside {[1:100]};
  }
endclass : base

class child extends base;
  constraint constraint_cn_c
  {
    data inside {[101:200]};
  }
endclass : child

module top();
  child C;
  initial begin
    C = new();
    if (!C.randomize()) begin
      $display("Randomization failed");
    end
    else begin
      $display("data = %0d", C.data);
    end
  end
endmodule : top

Tool will give compilation error like,
Solver failed when solving following set of constraints
 
rand bit[31:0] data; // rand_mode = ON
constraint constraint_cn    // (from this) (constraint_mode = ON) (top.sv:5)
{
   (data inside {[1:100]});
}
constraint constraint_cn_c    // (from this) (constraint_mode = ON) (top.sv:14)
{
   (data inside {[101:200]});
}

Tool will consider two different constraint so try to resolve both constraints because Same variable is constrained using two different constraint (Names are different so Child class can't override Base class's constraint) has their name is different and both constraints are contradict to each other.

Difference between typedef enum and only enum

module top();

  // create a data-type called on_off_e which is derived from enum type
  typedef enum bit {OFF, ON} on_off_e;
  // create a variable of enum
  enum bit {CLOSE, OPEN} switch_e;

  // create a variable of data-type on_off_e
  on_off_e on_off;

  // If you try to define variable of switch_e then tool will give compilation error because switch_e it self is a variable
  //switch_e switch_val;

  initial
  begin
    $display("on_off=%s, on_off=%b", on_off.name, on_off);
    $display("switch_e=%s, switch_e=%b", switch_e.name, switch_e);
  end

endmodule : top


Output:
on_off=OFF, on_off=0
switch_e=CLOSE, switch_e=0

Sunday 5 April 2015

Crontab in Linux (Cron job/Scheduled Task)

Crontab (CRON TAB) is a file which contains the schedule of cron entries to be run and at specified times.
 
On occasion, you might come across the need to create a scheduled task (Cron job) for your site. For example, you may want to run regression in weekend, you may want to send daily/weekly report.

Crontab will take the schedule and install it into an internal set of tables which it manages. At the appropriate time demanded by your schedule, another program called cron will execute the tasks you have set.


Crontab Restrictions

You can execute crontab if your name appears in the file /usr/lib/cron/cron.allow. If that file does not exist, you can use
crontab if your name does not appear in the file /usr/lib/cron/cron.deny.
If only cron.deny exists and is empty, all users can use crontab. If neither file exists, only the root user can use crontab. The allow/deny files consist of one user name per line.



Crontab Commands

Command
Usage
export EDITOR=vi (for bash)
setenv EDITOR vi (for csh)
To specify a editor to open crontab file
crontab –e
Edit your crontab file, or create if it doesn’t exist
crontab –l
Display your crontab file
crontab –r
Remove your crontab file
crontab –v
Display the last time you edited your crontab file
(this option is available on few systems)
crontab –u <user_name> -l
Display specific user’s crontab file
(sudo user access required)

Crontab File

Crontab Syntax:
A crontab file has 6 fields placed on a single line and separated by spaces, formatted as follows: 

<minute> <hour> <day> <month> <day-of-week> <command-line-to-execute>
      *            *         *            *               *               command to be executed
      |             |         |             |               |
      |             |         |             |               |
      |             |         |             |              +----- day of week (0 - 7) (Sunday=0 and 7)
      |             |         |             +------- month (1 - 12)
      |             |        +--------- day of month (1 - 31)
      |            +----------- hour (0 - 23)
     +------------- min (0 - 59)

The acceptable values for each of the 6 fields are:
Field
Range of Values
minute
0-59
hour
0-23
day
1-31
month
1-12
day-of-week
0-7 (where both 0 and 7 mean Sun,
1 = Mon, 2 = Tue, etc)
command-line-to-execute
The command to run along with the parameters to that command if any
 
The fields have to be in that exact order, with no empty or missing fields, and everything must be placed on a single line.

"Minute" is a number from 0 to 59. "Hour" is a number from 0 to 23. They represent the time of the day in a 24-hour day format, so for example, if you want a certain command to run at 5.30 am, you will have to code it as:
30 5
If you want something run at 8 pm, it has to be coded as
0 20
since 20:00 hours is 8 pm in the 24-hour time format.

"Day" and "month" refer to dates. "Day" takes a value between 1 and 31, and "month", as you may have already guessed, can take any value between 1 and 12. So if you want a command run on 5th January at 9.15 am, your schedule should begin with the following:
15 9 5 1

"Day-of-week" means basically which day you want your command to run. If you want your command to run on Sundays, use either 0 or 7 here. If you want it on Monday, use 1. (Note: if you are getting worried at this point how to combine all the various fields, some of which seem to contradict the other, don't worry. We're getting to that in Examples section)

Note
A. ) The specification of days can be made in two fields: month day and weekday. If both are specified in an entry, they are cumulative meaning both of the entries will get executed .
 



The trick to scheduling things, say, once a day, or once in 2 hours or the like, is to use a wildcard character. A wildcard character is like the Joker in a pack of playing cards, that is, it is something that can represent any card in the pack. In a crontab file, the wildcard character * (the asterisk), represents every possible value for the field.

If you want a particular program to run, say, once every day at 10.45 am, the time portion of the cron schedule should read:
45 10 * * *
Here's how to read the above line.
The first two fields "45 10" means that you want it to run at 10:45. The next field, the day field, is set to * (the asterisk character) to show that we're talking about 10.45 every day, not just the 1st of the month (which would be "1") or the 30th of the month ("30") or some other number. The month field is set to the asterisk as well. If we set some number in the month field, say "2", we will be saying that we only want the command to run at 10.45 in the month of February ("2").
Since that's not what we need, we put the asterisk to mean every month. Similarly, the day-of-week field is set to the asterisk, because we want the command to run whether it's Sunday ("0") or Monday ("1") or whatever day. 


Crontab Examples:  


Ex1:
A line in crontab file like below removes the tmp files from /home/someuser/tmp each day at 6:30 PM.
30     18     *     *     *         rm /home/someuser/tmp/*
Note
A. ) Important thing to note about this crontab line that we're constructing is that the entire line, schedule and command to execute, must fit into one line. You cannot put it into two lines for aesthetic reasons even if your command is very long.

Ex2:
If you want something to run once every two hours, you will have to use the slash, "/", character in your field. The slash character is the "step" character. In the case of a two hourly schedule, your time component of your cron file will read:
0 */2 * * *
The second field, "*/2", means every alternate hour.
Similarly, if you want something to run every 3 hours, you can change that field to "*/3", and so on.
Note
A. ) Repeat pattern like /2 for every 2 minutes or /10 for every 10 minutes is not supported by all operating systems. If you try to use it and crontab complains it is probably not supported.

Ex3:
If you want a particular command to run only at 8.00am on the 1st and 20th of every month, you should code the time as:
0 8 1,20 * *
The comma, ",", means "and". If you are confused by the above line, remember that spaces are the field separators, not commas.

Ex4:
What does the following schedule mean?
2 3 4,5 6 7
Decoded, the above line says at 3:02 am on the 4th and 5th of June (6) and on every Sunday (7), run your program.


Practical Examples:

Ex1: 
Cron Job everyday during working hours
This example checks the status of the database everyday (including weekends) during the working hours 9 a.m – 6 p.m
00 09-18 * * * /home/ramesh/bin/check-db-status
00 – 0th Minute (Top of the hour)
09-18 – 9 am, 10 am,11 am, 12 am, 1 pm, 2 pm, 3 pm, 4 pm, 5 pm, 6 pm
* – Every day
* – Every month
* – Every day of the week

Ex2:
Cron Job every weekday during working hours
This example checks the status of the database every weekday (i.e excluding Sat and Sun) during the working hours 9 a.m – 6 p.m.
00 09-18 * * 1-5 /home/ramesh/bin/check-db-status
00 – 0th Minute (Top of the hour)
09-18 – 9 am, 10 am,11 am, 12 am, 1 pm, 2 pm, 3 pm, 4 pm, 5 pm, 6 pm
* – Every day
* – Every month
1-5 -Mon, Tue, Wed, Thu and Fri (Every Weekday)


Crontab Environment Variables:

MAILTO="a@b.com,b@b.com"When your cron jobs have output, or, more importantly, when they fail, cron will send the output e-mail these addresses.
Ex1: Write following two lines into crontab file.
MAILTO="abc@xyz.com"
30     18     *     *     *         rm /home/someuser/tmp/*

Note:
Disable Email
By default cron jobs sends a email to the user account executing the cronjob. If this is not needed put the following command At the end of the cron job line .
>/dev/null 2>&1

MAILFROM="abc@xyz.com"
If it is defined then used as the mail sender address, otherwise, "root" is used.
LOGNAME=

CRON_TZ=IST
(IST = Indian Specific time)
specifies the time zone specific for the crontable. The user should enter a time according to the specified time zone into the table. The time used for writing into a log file is taken from the local time zone, where the daemon is running.
PATH="/usr/bin:/sbin:/bin"Logged in to the user account whose crontab you're setting up, go ahead and echo $PATH and copy those contents into the PATH variable of your crontab. Remember, this isn't a real script file, so you can't implicitly append :$PATH.
After assigning PATH and MAILTO, setting up your crontab is much easier.


HOME="/path/to/app/root"
The HOME variable tells which directory cron should execute the crontab commands from. Often times you'll have a user/crontab per project. If so, set the HOME variable to your project's root directory to avoid long, absolute paths to scripts or from having to 'cd /path/to/app/root && ...' for each job.

SHELL="/bin/bash"
Set the default shell to execute your commands from with the SHELL command. Like PATH, a safe bet is making this the same as your user's shell. Logged in as that user, run which `echo $0` to get an absolute path to your shell.

Generate log file

To collect the cron execution execution log in a file :
30 18 * * * rm /home/someuser/tmp/* > /home/someuser/cronlogs/clean_tmp_dir.log


How to be notified of errors

Since you are running your script as a scheduled task, there will be nobody there to view its output. By default, cron will send any output from the script in an email to you, if it knows your email address.

If your script is very talkative, and issues all sort of information when it executes, you'll probably want to shut it up (unless you are starved for email messages). To do this, we need to send all the normal output to a place called "/dev/null" which is basically like a black hole. It accepts anything you dump there, but you will never see it again. In the case of our first example, modify the command line to read:
30 11 * * * /your/directory/whatever.pl >/dev/null

The ">" sign means to redirect every normal message sent to screen to whatever is next in the command line, which, in our case, is /dev/null. If your script is designed to work correctly in a Unix environment, only the normal output will be swallowed up. Error messages will still be processed by the cron program. This is desirable, since you will want to informed when something is wrong so that you can fix the problem.

To receive the remaining unredirected messages, you will need to add another line to your crontab schedule to specify your email address. Use the following format:
MAILTO=email@example.com
30 11 * * * /your/directory/whatever.pl >/dev/null


The MAILTO line must be on a separate line. It is optional. That is, you don't have to specify it if you don't want to. Depending on how your web host has set up the system, cron might still be able to successfully send you error messages. If you really don't want to hear from cron at all, you will need to make your MAILTO line look like this:
MAILTO=""
That is, after the equal sign, put two double quotation marks without any space between them.


Special String:

Cron also offer some special strings,


String
Meaning
@reboot
Run once, at startup
@yearly
Run once a year, (0  0  1  1  *)
00:00 on Jan 1st for every year.
@annually
(same as @yearly)
@monthly
Run once a month, (0  0  1  *  *)
00:00 on 1st of every month.
@weekly
run once a week, (0  0  *  *  0)

@daily
Run once a day, (0  0  *  *  *)
00:00 on every day.
@midnight
(same as @daily)
@hourly
Run once an hour
(0  *  *  *  *)
Usage: "@reboot /path/to/execuable1" will execute /path/to/executable1 when the system starts. See "man 5 crontab" for more info.


Typical Example of Crontab file:

 

# use /bin/sh to run commands, no matter what /etc/passwd says
SHELL=/bin/sh
# mail any output to `paul', no matter whose crontab this is
MAILTO=paul
#
CRON_TZ=Japan
# run five minutes after midnight, every day
5 0 * * *       $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
# run at 2:15pm on the first of every month -- output mailed to paul
15 14 1 * *     $HOME/bin/monthly
# run at 10 pm on weekdays, annoy Joe
0 22 * * 1-5    mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
5 4 * * sun     echo "run at 5 after 4 every sunday"
# open terminal at start-up
@reboot  gnome-terminal