Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Using Fedora
FedoraForum Search

Forgot Password? Join Us!

Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 27th November 2012, 07:03 PM
pindakoe Offline
Registered User
 
Join Date: Dec 2011
Posts: 32
linuxchrome
printf not working in scripts called from cron

I have a script that prints a list of numbers which sometimes go up to a few Gb. For clarity I use printf %'15d as format (thouand separators). When calling this script from command-line it works as advertised:
Code:
/home/*/.cache/sessions                        9,616 
/home/*/.cache                               464,526 
/home/*/.local/share/Trash                57,425,266
However when (ana)cron starts it (as root) I do not get thousand separators.

I have been thinking this has to do with the shell under which this runs (printf being a built-in in bash), but (1) the script starts with #!/bin/bash, (2) /bin/sh is anyway a symlink to /bin/bash, (3) no change when I manually set shell=/bin/bash in /etc/anacrontab or /etc/crontab and (4) a printenv in the script confirms it to have bash as shell. Any clues?
Reply With Quote
  #2  
Old 27th November 2012, 08:20 PM
mtk Offline
Registered User
 
Join Date: Apr 2004
Posts: 127
linuxchrome
Re: printf not working in scripts called from cron

the '%' character is special in crontabs. it is converted to a newline. it has to be quoted with '\' to remain a real '%'.
i.e. printf \%'15d'.

/mark
Reply With Quote
  #3  
Old 27th November 2012, 09:12 PM
cazo Offline
Registered User
 
Join Date: Sep 2005
Location: Redneck Riviera
Posts: 334
linuxchrome
Re: printf not working in scripts called from cron

I believe it has something to do with 'locale' (but don't ask me to explain it).

Try adding
Code:
LC_NUMERIC=en_US.utf8
(or whatever your locale is set to) to the cron script.

I tried a simple batch file (run from cron) and got commas with that setting. Putting a locale command at the top showed that the script has LC_ set as POSIX. This would be the equivalent of
Code:
LC_NUMERIC=POSIX printf "%'15d\n" 57425266
(which doesn't show thousands separators).

Last edited by cazo; 28th November 2012 at 01:55 AM. Reason: clarification
Reply With Quote
  #4  
Old 28th November 2012, 06:50 PM
pindakoe Offline
Registered User
 
Join Date: Dec 2011
Posts: 32
linuxchrome
Re: printf not working in scripts called from cron

Done some testing. Thanks cazo -- changing the locale (or at least the numeric formatting) works. Obvious once you think about it. @mtk -- quoting the % with a backslash did not make any difference, but possibly because the formatting string was already between double quotes:

Code:
printf "%'d\n" 1245 produces 1'245
printf "\%'d\n" 1234 produces \1'245
Both assume that LC_NUMERIC has been set to en_US.utf8
Reply With Quote
Reply

Tags
called, cron, printf, scripts, working

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nautilus Scripts Not Working kwanbis Using Fedora 2 5th January 2010 04:20 PM
Gimp scripts are not working. _christian_ Using Fedora 9 10th June 2009 06:25 PM
CGI scripts not working Mucker Servers & Networking 23 31st July 2008 01:43 AM
noob: cron job scripts gold Using Fedora 1 10th September 2007 09:49 PM
Cron is not working, please help! kosh Using Fedora 10 1st August 2007 01:46 PM


Current GMT-time: 02:21 (Thursday, 20-06-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat