Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Question Bash: Adding crontab

    Hi, this is me again

    Is there any way to autoaticaly adding/remuving spesific crontab job to with the bash script?


  2. #2
    append whatever the job is to the crontab file. Or edit the crontab file and put it back.

  3. #3
    Good, how can I find the crontab? Last time I seen it at the level of user mail folder, but I have no Idea now where it is... im not an expert on linux things (yet)

  4. $spacer_open
  5. #4
    Linux Engineer Javasnob's Avatar
    Join Date
    Jul 2005
    Usually a program called crontab is available. So to change your crontab, do this:
    crontab -e
    Flies of a particular kind, i.e. time-flies, are fond of an arrow.

    Registered Linux User #408794

  6. #5
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Seattle, WA, USA
    You can set a specific file to be the crontab by using the "crontab FILE" command. So you could potentially use "crontab -l", store that output, append the new lines, and then pipe it into crontab.

    Check the man page for more info.

  7. #6


    1) How can I find defult file?
    2) How about if I want to remove spesific job? I thought to add commented part at the end and use grep to fing the line tha i need by using comment that I added or something like that, or actually I think I can use the file name taht is to be executed to find the line. So that should be like this

    PHP Code:
    if (ckek if job exist){
    buffer=get "crontab -l" 
    grep "my line w/ job"
    substruct my line from buffer [HOW DO DO THAT?]
    buffer=get "crontab -l" 
    $buffer=$buffer "my new job"
    write $buffer to croontab file [HOW to do that]

    hmm that thing that suppose too look like a script looks too messy, I have no idea how to do half of it, maybe I should do the operations in PHP, I just need to know the defult location of the crontab file, or way to find it out.

  8. #7
    Be careful editing cron through a script. Someone could use your script and put some nasty stuff in cron.

    Linux crontab files are generally in /var/spool/cron/tabs but that can vary by distro. The crontabs are also only accessible by root which means your script has to run as root which can be dangerous.

  9. #8
    ok i found my folder here: /var/cron/tabs
    What if dont have any file there and if I just put my text file there, would it be automaticaly be treated as crontab or do i have to declare it in command line?

    If crontabs are not secure how can I make the script that will allow yser to execute another defined script every x minutes?

  10. #9
    Just google for "crontab examples".
    A link with some examples:


  11. #10
    ok thanks i got it w/ php

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts