#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Location
    Leicester
    Posts
    7
    Rep Power
    0

    passing argument in cron job


    I am new to cron, and need some advice. I currently have a shell script which runs like the example shown below. There are 4 of these duplicates I want to run. But I want to pass an arguement so that it changes to a different user-id within the script

    0,5,10,15,20,25,30,35,40,45,50,55 ***** /../../../test.sh 2 [want to add an argument here for example $userid=xyz] >&1.

    Now in this shell script there is a variable which needs to be changed when the cron job runs.

    Example in shells script:

    $user-id = (this needs to be defined from the cron job)


    Can anyone help with this.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Middle Europa
    Posts
    1,200
    Rep Power
    13
    yes you need advice.

    this is wrong:
    0,5,10,15,20,25,30,35,40,45,50,55 *****
    see man pages crontab
    this is not really intelligent
    0,5,10,15,20,25,30,35,40,45,50,55
    and this is inpossible
    /../../../test.sh
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    USA
    Posts
    334
    Rep Power
    11
    First never use relative paths in cron jobs i.e. /../../../test.sh
    Always provide the full path i.e. /home/fpm/test.sh

    Second, you can pass arguments to test.sh but it is up to
    test.sh to interpret them as command line arguments.

    Form a typical crontab(5) manpage ....

    The ``sixth'' field (the rest of the line) specifies the
    command to be run. The entire command portion of the
    line, up to a newline or % character, will be executed by
    /bin/sh or by the shell specified in the SHELL variable of
    the cronfile. Percent-signs (%) in the command, unless
    escaped with backslash (\), will be changed into newline
    characters, and all data after the first % will be sent to
    the command as standard input.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Middle Europa
    Posts
    1,200
    Rep Power
    13
    fpmurphy:
    First never use relative paths in cron jobs i.e. /../../../test.sh
    is that a relative path ?
    IMO it's very absolute
    pointing to an absolutely impossible path
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    thank you!


    fpmurphy, your post gave me the answer to my issue immediately. it's remarkable because you pasted in the part of the manpage that would help me (regarding %). if you hadn't done that, i'd still be looking.

    i definitely need to start reading manpages first... they always surprise me with how informative they are.

IMN logo majestic logo threadwatch logo seochat tools logo