AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.

 View Only
Expand all | Collapse all

Output from crontab vs. command

  • 1.  Output from crontab vs. command

    Posted Mon December 05, 2022 02:09 AM
    Noticed a strange thing recently and hopefully someone of you might have an answer that can help me (?). I run backup command using crontab and I could see a difference in the file name when the command run via crontab and the command run manually.

    When I run the command manually the file name is correct, but when I run via crontab the file name is formatted without most of the parameters.

    Command found in crontab:
    /usr/sbin/backup -0 -u -f /mnt/aix-backup/$(hostname)-$(date "+%Y.%m.%d-%H.%M.%S")-root-WFB.bk /

    Output from command and crontab: (do not mind the strange box at the file name - just a special character in our language)



    So I can copy the command line from crontab and run manually and the file is created as expected. As screenshot the issue affects mksysb backup also, I use the same variables for the all the commands $(hostname)-$(date "+%Y.%m.%d-%H.%M.%S").

    ------------------------------
    Per Hillerström
    ------------------------------


  • 2.  RE: Output from crontab vs. command

    Posted Mon December 05, 2022 11:55 AM
    I suspect a locale setting. Run locale in your local shell where this is working as expected, and run locale in your cron job.

    ------------------------------
    Dave Marquardt
    Sr. Software Engineer
    IBM
    Austin TX
    ------------------------------



  • 3.  RE: Output from crontab vs. command

    Posted Tue December 06, 2022 02:08 AM
    Thanks for your respone @Dave Marquardt ... the result was as below and the output has no difference. Perhaps it is the swedish language.

    # locale
    LANG=sv_SE
    LC_COLLATE="sv_SE"
    LC_CTYPE="sv_SE"
    LC_MONETARY="sv_SE"
    LC_NUMERIC="sv_SE"
    LC_TIME="sv_SE"
    LC_MESSAGES="sv_SE"
    LC_ALL=
    +++++++++++++++++++++++++++++
    # cat /tmp/localecommand.log
    LANG=sv_SE
    LC_COLLATE="sv_SE"
    LC_CTYPE="sv_SE"
    LC_MONETARY="sv_SE"
    LC_NUMERIC="sv_SE"
    LC_TIME="sv_SE"
    LC_MESSAGES="sv_SE"
    LC_ALL=


    ------------------------------
    Per Hillerström
    ------------------------------



  • 4.  RE: Output from crontab vs. command

    Posted Tue December 06, 2022 08:37 AM
    That eliminates that idea!

    ------------------------------
    Dave Marquardt
    Sr. Software Engineer
    IBM
    Austin TX
    ------------------------------



  • 5.  RE: Output from crontab vs. command
    Best Answer

    Posted Tue December 06, 2022 01:09 PM
    The percent sign has a special meaning in a crontab.  Check the man page for details, but the chase is that you need to escape the percent sign with a backslash.  So the argument to the 'date' command should be "\%Y.\%m.\%d-\%H.\%M.\%S".

    ------------------------------
    Anker Lerret
    Blue Cross Blue Shield of Massachusetts
    ------------------------------



  • 6.  RE: Output from crontab vs. command

    Posted Wed December 07, 2022 02:52 AM
    Many thanks @Anker Lerret that solved it!​

    ------------------------------
    Per Hillerström
    ------------------------------



  • 7.  RE: Output from crontab vs. command

    Posted Wed December 07, 2022 10:02 AM
    Cheers!  I've shot off that toe before.

    ------------------------------
    Anker Lerret
    Blue Cross Blue Shield of Massachusetts
    ------------------------------



  • 8.  RE: Output from crontab vs. command

    Posted Thu December 08, 2022 02:17 AM
    Just out of curiosity. Would single quotes work as wel? I know in ksh/bash it should.

    ------------------------------
    Ane-Pieter Wieringa
    ------------------------------



  • 9.  RE: Output from crontab vs. command

    Posted Thu December 08, 2022 08:54 AM
    According to the man page, it has to be a backslash.  cron is a different animal from ksh/bash.

    ------------------------------
    Anker Lerret
    Blue Cross Blue Shield of Massachusetts
    ------------------------------