Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
Hi, this is me again Is there any way to autoaticaly adding/remuving spesific crontab job to with the bash script? Thanks!...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2006
    Posts
    70

    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?

    Thanks!

  2. #2
    Just Joined!
    Join Date
    Nov 2006
    Posts
    45
    append whatever the job is to the crontab file. Or edit the crontab file and put it back.

  3. #3
    Just Joined!
    Join Date
    Jul 2006
    Posts
    70
    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. #4
    Linux Engineer Javasnob's Avatar
    Join Date
    Jul 2005
    Location
    Wisconsin
    Posts
    942
    Usually a program called crontab is available. So to change your crontab, do this:
    Code:
    crontab -e
    Flies of a particular kind, i.e. time-flies, are fond of an arrow.

    Registered Linux User #408794

  5. #5
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    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.

  6. #6
    Just Joined!
    Join Date
    Jul 2006
    Posts
    70

    Post

    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?]
    }else{
       
    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.

  7. #7
    Just Joined!
    Join Date
    Nov 2006
    Posts
    45
    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.

  8. #8
    Just Joined!
    Join Date
    Jul 2006
    Posts
    70
    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?

  9. #9
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Just google for "crontab examples".
    A link with some examples:

    http://www.pantz.org/os/linux/programs/cron.shtml

    Regards

  10. #10
    Just Joined!
    Join Date
    Jul 2006
    Posts
    70
    ok thanks i got it w/ php

Page 1 of 2 1 2 LastLast

Posting Permissions

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