Skip to main content
Chemistry LibreTexts

4: crontab.scr

  • Page ID
    434731
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)

     

    Crontab Template

    We will start with a completely commented out crontab.scr file developed by Phil Williams and posted to github "Example-crontab-for-Raspberry-Pi".   To initialize your crontab with this file type the following code (which is the first commented out line of the file), but do not do this until you check your crontab, as it will overide your existing crontab.  The advantage of this template is that ir provides the structure for crontab statements.

    # crontab crontabRPi.scr
    # string             meaning
    # ------           -----------
    # @reboot      Run once, at startup.
    # @yearly       Run once a year, "0 0 1 1 *".
    # @annually    (same as @yearly)
    # @monthly    Run once a month, "0 0 1 * *".
    # @weekly     Run once a week, "0 0 * * 0".
    # @daily        Run once a day, "0 0 * * *".
    # @midnight   (same as @daily)
    # @hourly      Run once an hour, "0 * * * *".
    # The following line runs at boot time.  It firsts sleeps then touches the temp file.
    #@reboot  sleep 60s;touch /home/pi/touch.tmp
    # Having some program start running at boot time is useful.
    # Examples include starting a pitunnel, emailing data to the users like the current IP address.
    # minute (0-59),
    # |     hour (0-23),
    # |     |       day of the month (1-31),
    # |     |       |       month of the year (1-12),
    # |     |       |       |       day of the week (0-7 with 0=7=Sunday).
    # |     |       |       |       |           command(s)
    # |     |       |       |       |           |
    # |     |       |       |     Day of        |
    #Mins  Hours  Days   Months  the week    command(s)
    #0,30    *      *       *       *      /opt/vc/bin/vcgencmd measure_temp >> /home/pi/outCPUtemp.dat
    ## Every day, every hour, at the top and bottom of the hour run the command.
    #15,45    *      *       *       *      echo -n $(date), >> /home/pi/date,throttled.csv;/opt/vc/bin/vcgencmd get_throttled >> /home/pi/date,throttled.csv
    #0,30    *      *       *       1-6      /opt/vc/bin/vcgencmd measure_temp >> /home/pi/outCPUtemp.dat
    #        Never on Sundays, no 0 or 7
    #0,30    7-22   *       *       *      /opt/vc/bin/vcgencmd measure_temp >> /home/pi/outCPUtemp.dat
    #  Only runs between 7 am and 10 pm. Does not run while I am sleeping.
    

     

    Crontab Activity

    Create a folder

    Before we do anything you should set up your file directory so you know where your files are.  I suggest you create a folder called 0_crontab and in it place the crontabRPi.scr file, along with any Python files you may run with a Cron Job.

    clipboard_e54d0ef9cadc28dba0e423083338de8b9.pngFigure \(\PageIndex{1}\): Note we created a directory called 0_crontab and all files in this directory have the path /home/pi/Programs/0_crontab . (CC 0.0 Belford)

     

    Download template from git

    We can download the above file from the command line using the following command, which will download a folder into the current working directory (location of the command prompt).

    git clone https://github.com/phwilliams256/Example-crontab-for-Raspberry-Pi.git
    

    navigate to inside of the directory

    cd Example-crontab-for-Raspberry-Pi
    

    using the mv command move the file up one directory level (to the directory you wish to keep your files you run cron in.)

    mv /home/pi/Programs/0_crontab/Example-crontab-for-Raspberry-Pi/crontabRPi.scr /home/pi/Programs/0_crontab/
    

    now move the prompt up one level

    cd ..
    

    list files and then delete the folder.  You had left the read-me file in the folder and so you must delete recursively.  Remember, you can type E and then <tab> and it will autocomplete the directory name (if there are no other files or directories that start with the letter E).  It may ask you to remove write protected files, which you will do.

    ls
    rm -r Example-crontab-for-Raspberry-Pi/
    

    now you can look at the .scr file

    nano crontabRPi.scr
    
    clipboard_e0acae7b13fd563286d0779e28c0d04ed.pngFigure \(\PageIndex{1}\): Copy and Paste Caption here. (Copyright; author via source)
    Note

    After you used the "git clone" command you could have used the file manager (and right clicks) to make folders, move files and delete folders or files.

    Update crontabRPi.scr

    Open your crontab and see if there were any scripts you were running that you want to preserve.  You need to copy these from your crontab to crontabRPi.scr.  

    crontab -e
    

    Note: You do not have a crontab file if it asks what editor you want to use, and I suggest you use nano.  If you had created a crontab to email your IP address on bootup you need to copy that code to your crontabPRi.scr file (and any other code cron was running)

    clipboard_ea2d589625a750ed8897488b59a5851ea.pngFigure \(\PageIndex{1}\): Note the last line was not commented out and we want to copy it to the .scr file, so we can preserve it (Belford cc0.0)

    The following line is now added to the crontabRPi.scr file  You can do this with the nano editor from the command line.

    @reboot sleep 60 ; python3 /home/pi/Programs/0_crontab/send_my_ipaddress.py
    
    Note

    You can edit the crontab.src file by right clicking on it in the desktop mode and choosing text editor.  

    Initialize crontab 

    We now want to initialize the crontab with the content of crontab.scr.

    crontab crontabRPi.scr
    
    # Confirm the changes.
    crontab -l
    

    From now on in, you will alter the crontabRPi.scr file when you want to change what cron does, and then initialize the crontab.  This gives you a backup file of your cron settings and is much wiser than editing the crontab directly.

     

     


    4: crontab.scr is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?