Professional Web Applications Themes

su and crontab - Linux / Unix Administration

Need to invoke "crontab" while running as "root" but setup a cron table for another user. Tried the following: su - <username> -c "crontab <filename>" And get a message back "cannot read your cron file", i.e., as if the <filename> argument was ignored and "-l" presumed instead. Is there a way to do this? Thanks....

  1. #1

    Default su and crontab

    Need to invoke "crontab" while running as "root" but setup a cron table
    for another user. Tried the following:

    su - <username> -c "crontab <filename>"

    And get a message back "cannot read your cron file", i.e., as if the
    <filename> argument was ignored and "-l" presumed instead.

    Is there a way to do this?

    Thanks.

    FrankNatoli Guest

  2. #2

    Default Re: su and crontab

    FrankNatoli wrote: 
    As root, crontab -e <user>
    eg, crontab -e lp

    Mike Guest

  3. #3

    Default Re: su and crontab

    Thanks, but I'm afraid I left out a key requirement, i.e., that the
    solution works in a shell script. "crontab -e lp" of course opens a
    console edit session which is NG.

    FrankNatoli Guest

  4. #4

    Default Re: su and crontab

    On 2005-11-21, FrankNatoli wrote: 

    Requirement for what?

    Please read: <http://cfaj.freeshell.org/google>
     


    --
    Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
    Shell Scripting Recipes: | My code in this post, if any,
    A Problem-Solution Approach | is released under the
    2005, Apress | GNU General Public Licence
    Chris Guest

  5. #5

    Default Re: su and crontab

    Found what was wrong.

    su - <username> -c "crontab <filename>"

    needs a full path for <filename>. Current directory is NG. Even
    "./filename" doesn't work. Need full path.

    FrankNatoli Guest

  6. #6

    Default Re: su and crontab

    On 21 Nov 2005 14:58:33 -0800, FrankNatoli <att.net> wrote: 

    You're... editing a crontab...from within a script.

    First: why?

    Second: why not just, then, read it in, make the changes, and write it
    out as a file? crontab -e gives you syntax checking, but the crontab
    is, after all, just a file. You may even have some option for crontab
    which is "validate syntax of existing crontab file".

    Dave Guest

  7. #7

    Default Re: su and crontab

    The script is installing a software package. One element of the
    installation is setting up a crontab entry. Although the installation
    is being run as "root", the software package will run as an ordinary
    user, hence the need to setup a crontab entry while installing as root
    for a non-root user.

    Had I not found what was wrong with my original arguments, i.e., the
    need to specify a full path for the crontab argument, I would probably
    have done as you suggest, i.e., directly edit the system cron file.

    FrankNatoli Guest

  8. #8

    Default Re: su and crontab

    In article <googlegroups.com>,
    "FrankNatoli" <att.net> wrote:
     

    You're probably confused about what the current directory is when the
    crontab command is being run. I don't think su changes to the target
    user's home directory, so it's looking for <filename> in root's home
    directory.

    --
    Barry Margolin, mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    Barry Guest

  9. #9

    Default Re: su and crontab

    > "FrankNatoli" <att.net> wrote: [/ref]

    Barry Margolin <mit.edu> wrote: 

    I think the '-' parameter to su DOES cause it to change to the target user's
    home directory. If that's different than the current directory, you'll need a
    more complete path to <filename>.
    --
    Mark Rafn net <http://www.dagon.net/>
    Mark Guest

Similar Threads

  1. Crontab
    By Antigoni in forum Linux / Unix Administration
    Replies: 2
    Last Post: June 4th, 12:15 PM
  2. Crontab Problem
    By Kidus in forum UNIX Programming
    Replies: 2
    Last Post: September 8th, 10:57 PM
  3. crontab log
    By NIr in forum Sun Solaris
    Replies: 2
    Last Post: August 27th, 11:02 PM
  4. crontab bug?
    By LeVA in forum Debian
    Replies: 1
    Last Post: August 4th, 12:10 AM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139