|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
Crontab is not working in printf
hi, i have a script as: printf '%s -> %s\n' "$(date '+%Y-%m-%d %H:%M')" "$(/opt/gcsw/status -ne | fgrep 'State:2' | wc)" which gives output as: 2013-01-18 13:00 -> 80 480 6529 and it is working fine. now I want to put this into cronjob and write the output to a file in every 5 minutes: Code:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * printf '%s -> %s\n' "$(date '+%Y-%m-%d %H:%M')" "$(/opt/gcsw/status -ne | fgrep 'State:2' | wc)" >> /var/tmp/gcsw/status.txt i want to see the output as: Code:
2013-01-18 13:00 -> 80 480 6529 2013-01-18 13:05 -> 85 480 6529 2013-01-18 13:10 -> 80 423 6329 2013-01-18 13:15 -> 71 460 6129 ... but file is not being updated i think there is a problem with printf with cronjob. any help?
Last edited by gc_sw; 01-21-2013 at 04:18 AM.. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Any error msgs? Pls keep in mind that processes launched by
cron run in a reduced environment, and perhaps in another shell, so are you sure all commands are on the
PATH var?
|
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
there is not any error message but file is not being updated
i didnot assign anything with
PATH how can i solve it? |
|
#4
|
|||
|
|||
|
a) did you look into the
syslog files for
cron entries?
b) enter PATH=... into crontab (cf man crontab ) |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
a) there is no entry related to cron in
syslog b) $PATH is defined as Code:
/usr/sbin:/usr/bin:/usr/ccs/bin:/usr/openwin/bin:/usr/dt/bin:/usr/platform/SUNW,Sun-Fire-T200/sbin:/opt/SUNWexplo/bin:/opt/SUNWsneep/bin:/opt/CTEact/bin can we modify the command without using printf ? |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
The % character has a special meaning in crontab entries. Code:
man crontab ... You need to escape each % as \%; 'text1%text2' becomes 'text1'\%'text2' and "text3%text4" becomes "text3"\%"text4" (i.e. two strings with a \% in between). Code:
printf '%s -> %s\n' "$(date '+%Y-%m-%d %H:%M')" ... becomes Code:
printf \%'s -> '\%'s\n' "$(date '+'\%'Y-'\%'m-'\%'d '\%'H:'\%'M')" ... This is so ugly that you better put the original code in an executable script, and run the script from the crontab. Last edited by MadeInGermany; 01-21-2013 at 06:48 AM.. |
| The Following 2 Users Say Thank You to MadeInGermany For This Useful Post: | ||
Corona688 (01-21-2013), elixir_sinari (01-21-2013) | ||
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
i have created a file (/var/tmp/gcsw/script.sh) and write: Code:
printf '%s -> %s\n' "$(date '+%Y-%m-%d %H:%M')" "$(/opt/gcsw/gwstatus -ne | fgrep 'State:2' | wc)" >> /var/tmp/gcsw/status.txt and created a cronjob as: Code:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /var/tmp/gcsw/script.sh but output /var/tmp/gokhan/status.txt is not correct. so cronjob is not working ![]() PS: when I manually run: Code:
printf '%s -> %s\n' "$(date '+%Y-%m-%d %H:%M')" "$(/opt/gcsw/gwstatus -ne | fgrep 'State:2' | wc)" >> /var/tmp/gcsw/status.txt it is successfully OK. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| crontab is not working!! | getrue | Red Hat | 14 | 09-08-2011 11:06 AM |
| crontab not working | shifahim | UNIX for Dummies Questions & Answers | 8 | 08-16-2011 08:22 AM |
| working of printf() | zius_oram | Programming | 7 | 08-28-2010 12:37 PM |
| crontab NOT working | baanprog | UNIX for Advanced & Expert Users | 2 | 09-26-2006 12:11 PM |
| crontab not working right | kymberm | UNIX for Dummies Questions & Answers | 3 | 07-09-2003 04:21 PM |
|
|