The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-30-2007
baanprog baanprog is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 22
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
  #2 (permalink)  
Old 03-30-2007
dennis.jacob dennis.jacob is offline Forum Advisor  
dj - the student
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 610
Quote:
Originally Posted by baanprog
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
The backslash not required...

[ `date '+%d'` -eq `cal | grep -v "^$" | tail -1 | awk '{print $NF-1}'` ] && do....what required..
  #3 (permalink)  
Old 03-30-2007
baanprog baanprog is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 22
still

The cron does not give any error, but i dont get the output file either...


regards
  #4 (permalink)  
Old 03-30-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
First, the backslash is required. From the crontab man page:
Quote:
The sixth field of a line in a crontab file is a string that is executed by the shell at the specified times. A percent character in this field (unless escaped by \) is translated to a NEWLINE character.
Some versions of cron are smart enough to remove that blackslash prior to passing it to the shell. Others just leave it there. So the shell will see:
[ \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

  #5 (permalink)  
Old 03-30-2007
awk awk is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:10 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0