Results 1 to 4 of 4

Thread: Is there a way to automatically create root's crontab?

  1. #1
    Join Date
    May 2005
    Location
    Russia
    Beans
    537

    Is there a way to automatically create root's crontab?

    Good day, my old friends!
    I make a server postinstall script that copies my config files and all... I want to create an empty crontab for root if needed. My solution is very awkward. Here is it:
    Code:
    createCrontab() {
    if [ ! -f /var/spool/cron/crontabs/root ]; then
    sudo EDITOR=vi crontab -e 2>/dev/null <<END-OF-INPUT
    :g/hello/s//bye/g
    :w
    :q!
    END-OF-INPUT
    fi
    }
    If you have any idea how to handle it in a more civilized way - please tell me! Thank you in advance!

  2. #2
    Join Date
    Nov 2006
    Location
    Belgium
    Beans
    3,025
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Is there a way to automatically create root's crontab?

    don't really understand what you're trying to do.

    There is a systemwide crontab : /etc/crontab.
    Normally you'd just add to that, no ?

    if you just want to make an empty file (from a script), you'd go

    Code:
    touch /path/to/file
    . That creates a file if it doesn't exist yet ' if it exists, it just modifies the 'last accessed' date)

    you can also do
    Code:
    echo > /path/to/file
    this creates an empty file, overwriting /path/to/file if it already exists

    to add text to a file, you'd go something like
    Code:
    cat >>path/to/file <<EOF
    
    blah
    blah blah
    bla...
    
    EOF

  3. #3
    Join Date
    May 2005
    Location
    Russia
    Beans
    537

    Re: Is there a way to automatically create root's crontab?

    Quote Originally Posted by koenn View Post
    if you just want to make an empty file (from a script), you'd go

    Code:
    touch /path/to/file
    . That creates a file if it doesn't exist yet ' if it exists, it just modifies the 'last accessed' date)
    Touch creates REALLY empty file with zero length. Can you explain me how to add anything with sed to an empty file?
    you can also do
    Code:
    echo > /path/to/file
    this creates an empty file, overwriting /path/to/file if it already exists
    This doesn't work with sudo.
    to add text to a file, you'd go something like
    Code:
    cat >>path/to/file <<EOF
    
    blah
    blah blah
    bla...
    
    EOF
    This doesn't work with sudo also...

  4. #4
    Join Date
    Nov 2006
    Location
    Belgium
    Beans
    3,025
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Is there a way to automatically create root's crontab?

    Quote Originally Posted by PryGuy View Post
    Touch creates REALLY empty file with zero length. Can you explain me how to add anything with sed to an empty file?
    - you said you want an empty file
    - it's beyond me why you'd use sed to add text an empty file, and I don't know how to do that anyway.


    Quote Originally Posted by PryGuy View Post
    This doesn't work with sudo.This doesn't work with sudo also...
    so why not run the entire script with sudo ?

Bookmarks

Posting Permissions

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