Calender Unix programming date issues


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calender Unix programming date issues
# 1  
Old 05-02-2008
Calender Unix programming date issues

Hi, i;m beginner of Unix, i trying to use crontab to zip my log file automatically, below is my coding, some of the statement i don't know whether is correct or not. Pls helpSmilie

year=`date '+%Y'`
month=`date '+%m'`
day=`date '+%d'`
day=`expr $day - 1`

case $month in
1 | 3 | 5 | 7 | 8 | 9 | 10 | 12);;
if [ $day = 0 ]; then
day=32
day1=$day-1
fi

4 | 6 | 11);;
if [ $day = 0 ]; then
day=31
day1=$day-1'
fi

2);;
if [ $month Mod 4 =0]; then
if[ $day = 0 ]; then
day = 30
day1 =%day-1
fi
else
if[ $day = 0 ]; then
day = 29
day1 =$day-1'
fi
fi

*) echo error: too many arguments 1>&2 ;;
esac

DATE=$year$month$day1
mv $HOME/*$DATE*log $HOME/archive
cd $HOME/archive
gzip *

Last edited by dannyd_y; 05-02-2008 at 06:03 AM..
# 2  
Old 05-02-2008
Please describe any bugs you get and ask specific questions. Nobody here will do the testing guy for you.

Why don't you simply use logratate which does exactly the same thing?
# 3  
Old 05-02-2008
Quote:
Originally Posted by dannyd_y
Hi, i;m beginner of Unix, i trying to use crontab to zip my log file automatically, below is my coding, some of the statement i don't know whether is correct or not. Pls helpSmilie

year=`date '+%Y'`
month=`date '+%m'`
day=`date '+%d'`
day=`expr $day - 1`

case $month in
1 | 3 | 5 | 7 | 8 | 9 | 10 | 12);;
if [ $day = 0 ]; then
day=32
day1=$day-1
fi

4 | 6 | 11);;
if [ $day = 0 ]; then
day=31
day1=$day-1'
fi

2);;
if [ $month Mod 4 =0]; then
if[ $day = 0 ]; then
day = 30
day1 =%day-1
fi
else
if[ $day = 0 ]; then
day = 29
day1 =$day-1'
fi
fi

*) echo error: too many arguments 1>&2 ;;
esac

DATE=$year$month$day1
mv $HOME/*$DATE*log $HOME/archive
cd $HOME/archive
gzip *
Use the code tags it will help in understanding the problem clearly with identation.
in tool box the hash button is for the code tags.

Thanks
# 4  
Old 05-02-2008
Buddy,

The code seems to be correct. But it needs certain modifications at some places. Please find below the corrected code:

year=`date '+%Y'`
month=`date '+%m'`
day=`date '+%d'`
day=`expr $day - 1`

case $month in
1 | 3 | 5 | 7 | 8 | 9 | 10 | 12);;
if [ $day = 0 ]; then
day=32
day1=`expr $day-1`
fi

4 | 6 | 11);;
if [ $day = 0 ]; then
day=31
day1=`expr $day-1`
fi

2);;
if [ `expr $month % 4` -eq 0]; then
if[ $day = 0 ]; then
day = 30
day1 =`expr $day-1`
fi
else
if[ $day = 0 ]; then
day = 29
day1 =`expr $day-1`
fi
fi

*) echo error: too many arguments 1>&2 ;;
esac

DATE=$year$month$day1
mv $HOME/*$DATE*log $HOME/archive
cd $HOME/archive
gzip *


Probably this would work. Just check out the differences with your code. Revert back in case of any issue.Smilie
# 5  
Old 05-05-2008
Smilie Thanks so much guys...i'll try it out.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date format issues

I would like to get the below in YYYY MMDD format, Last date of the week Last date of the month Last date of the year And then compare d_date with the above if it matches it has to send some email. while read email_address; do mail -s "$subject"... (1 Reply)
Discussion started by: Aditya_001
1 Replies

2. Shell Programming and Scripting

PERL, Date & Time issues

Hello All, This is my first script in PERL. Hence require your help in moving further. I have a script which should populate the values for Today, Yesterday output. For which I use timeFrame as a variable to obtain the time in hrs:mm as 10:00. All I want is, I want my timeFrame to start... (4 Replies)
Discussion started by: sathyaonnuix
4 Replies

3. Shell Programming and Scripting

Question on Autosys calender date.

Hi I am trying to schedule a job through Autosys through UNIX on a particular day of every month (for example 20th of every month). Can some one please help me whats the command or whats the process to run on that particular day of month. Thank you, (2 Replies)
Discussion started by: sravuri
2 Replies

4. UNIX for Dummies Questions & Answers

How does unix system administration, unix programming, unix network programming differ?

How does unix system administration, unix programming, unix network programming differ? Please help. (0 Replies)
Discussion started by: thulasidharan2k
0 Replies

5. UNIX for Dummies Questions & Answers

Help with date command in bash shell programming

Doubt #1 I have a program that I want the user to input date. When the user inputs the date, is it able to format it to system date dd-mm-yyy and then echo the value into a text file? Doubt#2 If the above is not going to work, I tried to have the system date appear in the user input field and... (6 Replies)
Discussion started by: frossie
6 Replies

6. UNIX for Dummies Questions & Answers

shell script programming issues

I'm having trouble running this script. I'm new to Unix so be kind please. #!/bin/sh # Test to make sure only a single parameter is passed from the # command line. if then echo "Usage: AC.sh <directory>" exit fi # Is the parameter a directory test if then echo... (3 Replies)
Discussion started by: FSUdude08
3 Replies

7. UNIX for Dummies Questions & Answers

Carreer:Networking Programming in Unix (C programming Language)

Hello, I am trying to learn Networking Programming in C in unix enviorment. I want to know how good it is to become a network programmer. i am crazy about Network programming but i also want to opt for the best carreer options. Anybody experienced Network Programmer, please tell me is my... (5 Replies)
Discussion started by: vibhory2j
5 Replies

8. UNIX for Dummies Questions & Answers

Date time issues on RHEL

Hi, I am facing a weird problem with the 'Date'. If I check date multiple times in a short interval I see a different time altogether. Here is an example $ date Tue Jul 15 02:07:22 PDT 2008 $ date Tue Jul 15 02:07:23 PDT 2008 $ date Tue Jul 15 03:20:42 PDT 2008 $ date Tue Jul 15... (5 Replies)
Discussion started by: sumitb74
5 Replies

9. Shell Programming and Scripting

convert Julian date to calender date

Hi, I have script in unix which creates a julian date like 126 or 127 I want convert this julian date into calender date ex : input 127 output 07/may/2007 or 07/05/2007 or 07/05/07 rgds srikanth (6 Replies)
Discussion started by: srikanthus2002
6 Replies

10. Shell Programming and Scripting

Unix Systems Programming Vs Unix Programming

Several months ago I found a link that explained the difference between how a Unix Systems Admin would do scripting compared to what a Unix Programmer would do. It showed a basic script and then show several iterations that explained how the Systems Admin would change it to make it better. I was... (0 Replies)
Discussion started by: BCarlson
0 Replies
Login or Register to Ask a Question