![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Conditional FTP | Dastard | Shell Programming and Scripting | 2 | 06-21-2008 08:38 AM |
| AWK - conditional cause | Rafael.Buria | Shell Programming and Scripting | 2 | 01-28-2008 01:24 PM |
| conditional split | braindrain | Shell Programming and Scripting | 5 | 03-11-2006 03:54 AM |
| Conditional File Movement script scheduled using CRON job | imu | Shell Programming and Scripting | 2 | 09-20-2005 07:30 AM |
| Conditional Statements | cstovall | Shell Programming and Scripting | 1 | 05-15-2005 06:58 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Conditional Cron
Hi, The following test in cron fails. Any clue? I want it to run last day before end of month Code:
34 13 * * * [ `date +'\%d'` -eq `cal | grep -v "^$" | tail -1 | awk '{print $NF-1}'` ] && /export/myshell.sh
Regards |
|
||||
|
Quote:
[ `date '+%d'` -eq `cal | grep -v "^$" | tail -1 | awk '{print $NF-1}'` ] && do....what required.. |
|
|||||
|
First, the backslash is required. From the crontab man page: Quote:
[ \30 -eq 30 ] Most shells will get that right but some versions of the bourne shell will not. You are probably using Solaris which has both behaviors. My advice is to put shell scripting into a shell script which is executed by a modern shell. If you must get this to work, use eval with the date command Code:
34 13 * * * [ `eval date +'\%d'` -eq `cal | grep -v "^$" | tail -1 | awk '{print $NF-1}'` ] && /export/myshell.sh
|
|
||||
|
running this in ksh seems to work -
[ $(TZ=GMT-48 date +%d) -eq "01" ] && echo true Of course, you will need to make adjustments if you are far from England. Basically, sets the date 48 hours ahead and does the date. Today, the 30th, comes up with 01, since march has 30 days. The cal routine would not work on months where the last day of the month was on Sunday, since that would be the first field, and $NF-1 would be the entire line (the last day), and not the day before. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|