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

    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0

    Unix snippet help


    Hi
    I want to execute this a script first sunday of every month

    00 02 * * 0 [ $(date +%d) -le 10 ] && {cd $HOME/local/rman;
    ./test.sh 1>/tmp/t.log 2>&1}

    But its showing following error in mail.

    [ $(date +

    produced the following output:

    sh: test: 0403-021 A ] character is missing.

    what am I doing wrong?

    Thanks
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0
    crontab entry not working
    37 11 * * * [ $(date "+%d") -lt 19 ] && echo "yes">/tmp/t.log

    but command line is working fine..
    racstg21:/usr/opt/oracle/local/rman[(oracle)()]>
    racstg21:/usr/opt/oracle/local/rman[(oracle)()]>[ $(date "+%d") -lt 19 ] && echo "yes">/tmp/t.log
    racstg21:/usr/opt/oracle/local/rman[(oracle)()]>
    racstg21:/usr/opt/oracle/local/rman[(oracle)()]>ls -l /tmp/t.log
    -rw-r--r-- 1 oracle oinstall 4 Sep 18 11:38 /tmp/t.log

    why is my snippet not working in crontab?
  4. #3
  5. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,379
    Rep Power
    1871
    crontab command lines are almost certainly interpreted as 'sh' command lines, rather than say bash.

    Since the $(cmd) notation is a bash extension as a readable version of `cmd`, perhaps you could try that instead.

    On the other hand, why not
    a) setup the crontab to only run the script on the requested days.
    b) setup a wrapper script which has the rather complicated test.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0
    Its working now.. with following syntax
    #09 12 * * * eval [ `date "+\%d"` -lt 19 ] && echo "yes" >/tmp/t.log

IMN logo majestic logo threadwatch logo seochat tools logo