Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Unable to convert date into no. using date -d +%s syntax in ksh shell Post 302652423 by Jcpratap on Thursday 7th of June 2012 06:34:11 AM
Old 06-07-2012
Hi Methyl,
sorry for typo ,the code is for gzipping the files.
ls -lart gives same o/p as ls -lrt

absolutely corrct ,i am trying to gzip files older than today which are of a certain pattern.
I will be setting a cron for this which will run at 2300 hrs everyday.
My script comapres the month first with todays date,then the day.
this script will fail on 1st jan as jan is assigned a no. 1 which is less than 12(dec),
so all files for dec 31st will no get gzipped.

also Please find the full code for sun OS 5.8

Code:
 
datecalc()
{
if [ $1 = "Jan" ]
then
return 1;
elif  [ $1 = "Feb" ]
then
return 2;
elif  [ $1 = "Mar" ]
then
return 3;
elif  [ $1 = "Apr" ]
then
return 4;
elif [ $1 = "May" ]
then
return 5;
elif  [ $1 = "Jun" ]
then
return 6;
elif  [ $1 = "Jul" ]
then
return 7;
elif  [ $1 = "Aug" ]
then
return 8;
elif [ $1 = "Sep"
then
return 9;
elif  [ $1 = "Oct" ]
then
return 10;
elif  [ $1 = "Nov" ]
then
return 11;
elif  [ $1 = "Dec" ]
then
return 12;
fi
}
v1=`ls -lrt | awk '{print $6,$7,$8,$9}'| egrep -v "gz$" |  egrep "MDCR.*" | wc -l`
v2=`date | awk '{print $2}'`
v3=`date | awk '{print $3}'`
datecalc $v2
v4=$?
i=1
while [ $i -le $v1 ]
do
A[$i]=`ls -lrt | awk '{print $6,$7,$8,$9}'| egrep -v "gz$" |  egrep "MDCR.*" | awk '{print $1}' | head -$i | tail -1`
B[$i]=`ls -lrt | awk '{print $6,$7,$8,$9}'| egrep -v "gz$" |  egrep "MDCR.*" | awk '{print $2}' | head -$i | tail -1`
C[$i]=`ls -lrt | awk '{print $9}'| egrep -v "gz$" |  egrep "MDCR.*" | awk '{print $1}' | head -$i | tail -1`
x=${A[$i]}
datecalc $x
v5=$?
y=${B[$i]}
if [ $v5 -lt $v4 ]
then
gzip ${A[$i]}
elif [ $v5 = $v4 && $y -lt $v3 ]
then
gzip ${A[$i]}
fi
i=`expr $i + 1`
done

thanks
jcpratap
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Newbie convert date ksh

If I have start = 02282006; end = 03152006; How do I get startdate = 02/28/2006; enddate = 03/15/2006; Thanks, (3 Replies)
Discussion started by: britney
3 Replies

2. 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

3. Shell Programming and Scripting

ksh compare dates INSIDE a file (ie date A is > date B)

In KSH, I am pasting 2 almost identical files together and each one has a date and time on each line. I need to determine if the first instance of the date/time is greater than the 2nd instance of the date/time. If the first instance is greater, I just need to echo that line. I thought I would... (4 Replies)
Discussion started by: right_coaster
4 Replies

4. UNIX for Dummies Questions & Answers

Unable to add date to current date.

Hi, I am trying to display future date from the current date but unable to do so in UNIX (not in PERL). For eg: if today is March 5 then I want a variable wherein I can store Mar 7 date, but unable to get the future date from the current date. I have tried many possible ways as mentioned below... (11 Replies)
Discussion started by: amit.mathur08
11 Replies

5. Shell Programming and Scripting

How to convert string(variable) into date( epoch) in ksh on HPUX machine?

Hi all, I have used a bash script which ultimately converts a string into date using date --date option: DATE=$DATE" "$TIME" "`date +%Y` //concatenating 2 strings TMRW_DATE=`date --date="$DATE" +"%s"` //applying date command on string and getting the unixtime Please use code tags... (7 Replies)
Discussion started by: Rashu123
7 Replies

6. Shell Programming and Scripting

Convert date arg to sql date

Doing a bcp load to sybase and need to convert datearg which comes in as 20130501 to 2013-05-01 which is the best way to do this (4 Replies)
Discussion started by: tasmac
4 Replies

7. Shell Programming and Scripting

Convert date into days using shell script

Hi, I have date format in an excel sheet as 07/03/2014 11:21. I need to check this date with current date and need to find whether it is more than 30 days or not. I know how to current date into days, but someone please help me to change the date in the excel sheet to days, so that i can check... (2 Replies)
Discussion started by: Arasu123
2 Replies

8. Shell Programming and Scripting

Convert a date stored in a variable to epoch date

I am not able to pass date stored in a variable as an argument to date command. I get current date value for from_date and to_date #!/usr/bin/ksh set -x for s in server ; do ssh -T $s <<-EOF from_date="12-Jan-2015 12:02:09" to_date="24-Jan-2015 13:02:09" echo \$from_date echo... (7 Replies)
Discussion started by: raj48
7 Replies

9. UNIX for Dummies Questions & Answers

Print start date to end date, given $1 & $2 in ksh

Dear all, I have an user passing 2 parameter 31/03/2015 and 02/04/2015 to a ksh script. How to print the start date to end date. Expected output is : 31/03/2015 01/04/2015 02/04/2015 Note : 1. Im using aix and ksh 2. I have tried to convert the given input into a date, didnt... (0 Replies)
Discussion started by: mr.rajaravi
0 Replies
DP(8)                                                                [nmh-1.5]                                                               DP(8)

NAME
dp - parse dates 822-style SYNOPSIS
/usr/lib/mh/dp [-form formatfile] [-format string] [-width columns] [-version] [-help] dates ... DESCRIPTION
Dp is a program that parses dates according to the ARPA Internet standard. It also understands many non-standard formats, such as those produced by TOPS-20 sites and some UNIX sites using ctime(3). It is useful for seeing how nmh will interpret a date. The dp program treats each argument as a single date, and prints the date out in the official 822-format. Hence, it is usually best to enclose each argument in quotes for the shell. To override the output format used by dp, the -format string or -format file switches are used. This permits individual fields of the address to be extracted with ease. The string is simply a format string and the file is simply a format file. See mh-format(5) for the details. Here is the default format string used by dp: %<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%> which says that if an error was detected, print the error, a `:', and the date in error. Otherwise, output the 822-proper format of the date. FILES
$HOME/.mh_profile The user profile PROFILE COMPONENTS
None SEE ALSO
ap(8), Standard for the Format of ARPA Internet Text Messages (RFC-822) DEFAULTS
`-format' default as described above `-width' default to the width of the terminal CONTEXT
None BUGS
The argument to the -format switch must be interpreted as a single token by the shell that invokes dp. Therefore, one must usually place the argument to this switch inside quotes. MH.6.8 11 June 2012 DP(8)
All times are GMT -4. The time now is 06:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy