Need help to use date in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help to use date in file
# 8  
Old 11-21-2012
Sorry should have said this script needs ksh or bash shell, do you have these available?
# 9  
Old 11-21-2012
this scripte cut lthe line expired in file var/etc/expired

## ##
grep $(date +%d-%m-%Y) /var/teste.cfg >> /var/expired
echo "sed -i '/$(date +%d-%m-%Y)/d' /var/teste.cfg" > /tmp/check-expire
chmod 755 /tmp/check-expire
/tmp/check-expire
rm /tmp/check-expire

can you add # befor the line F: in the my file : teste.cfg

---------- Post updated at 06:39 PM ---------- Previous update was at 06:37 PM ----------

bash shell

---------- Post updated at 06:43 PM ---------- Previous update was at 06:39 PM ----------
CCcam expire Date script

Put script file on
Code:
/bin/expiry
Code:
chmod 755 /bin/expiry
example of F Line on CCcam.cfg
Code:
F: user pass 0 1 0 { 0:0:1 } # 08-04-2012
cron job to check expire dates once daily
Code:
crontab -e
Code:
00 00 * * * /bin/expiry
finally when you will find expired lines on
Code:
/var/etc/expired
---------- Post updated at 06:57 PM ---------- Previous update was at 06:43 PM ----------

it's work
but the file is in /temp
thank's for all
but if i add after the date other information
exmp : #F: net350 1456564024 1 0 0 { 0:0:1 } # 26-2-2012 ; teste
it work or not
# 10  
Old 11-21-2012
Yes script gets everything after the last "-" as Year.


Try this:

Code:
#!/bin/ksh
YT=`date +%Y`
MT=`date +%m`
DT=`date +%d`
MT=${MT#0}
DT=${DT#0}
 
while read line
do
    Y=${line##*-}
    Y=${Y%% *}
    M=${line%-$Y}
    M=${M##*-}
    D=${line%-$M-$Y}
    D=${D##* }
    M=${M#0}
    D=${D#0}
 
    if [ -z "${line%%#*}" ] || [ $YT -lt $Y ] || [ $YT -eq $Y -a $MT -lt $M ] || [ $YT -eq $Y -a $MT -eq $M -a $DT -lt $D ]
    then
        echo "$line"
    else
        echo "#$line"
    fi
done < /var/teste.cfg > /tmp/teste.cfg
 
mv /tmp/teste.cfg /var/teste.cfg

This User Gave Thanks to Chubler_XL For This Post:
# 11  
Old 11-21-2012
the scripte work
but i have this message
Code:
/var/datecheek.sh: line 22: [: too many arguments
/var/datecheek.sh: line 22: [: too many arguments
/var/datecheek.sh: line 22: [: too many arguments
/var/datecheek.sh: line 22: [: too many arguments

---------- Post updated at 07:12 PM ---------- Previous update was at 07:11 PM ----------

Line 22
Code:
if [ -z "${line%%#*}" ] || [ $YT -lt $Y ] || [ $YT -eq $Y -a $MT -lt $M ] || [ $YT -eq $Y -a $MT -eq $M -a $DT -lt $D ]

the new file
Code:
#F: net101 3320200125 1 0 0 { 0:0:1 } # 24-2-2012 ; teste
#F: net102 2245604546 1 0 0 { 0:0:1 } # 24-2-2011 #
F: net103 2150516516 1 0 0 { 0:0:1 } # 24-2-2013
#F: net104 2241554654 1 0 0 { 0:0:1 } # 24-2-2012
#F: net105 2102313201 1 0 0 { 0:0:1 } # 24-2-2011
#F: net106 2021202220 1 0 0 { 0:0:1 } # 24-2-2011
#F: net107 3320012335 1 0 0 { 0:0:1 } # 24-2-2010
#F: net108 1456564024 1 0 0 { 0:0:1 } # 24-2-2012
F: net109 2410456644 1 0 0 { 0:0:1 } # 24-2-2013
F: net110 6669099896 1 0 0 { 0:0:1 } # 24-2-2013
#F: net125 2021202220 1 0 0 { 0:0:1 } # 24-2-2011
#F: net254 3320012335 1 0 0 { 0:0:1 } # 25-2-2010
#F: net350 1456564024 1 0 0 { 0:0:1 } # 26-2-2012
F: net555 2410456644 1 0 0 { 0:0:1 } # 24-2-2015


Last edited by Franklin52; 11-22-2012 at 04:12 AM.. Reason: Please use code tags for data and code samples
# 12  
Old 11-21-2012
OK this slight change so fix that:

Code:
#!/bin/ksh
YT=`date +%Y`
MT=`date +%m`
DT=`date +%d`
MT=${MT#0}
DT=${DT#0}
 
while read line
do
    Y=${line##*-}
    M=${line%-$Y}
    M=${M##*-}
    D=${line%-$M-$Y}
    Y=${Y%% *}
    D=${D##* }
    M=${M#0}
    D=${D#0}
 
    if [ -z "${line%%#*}" ] || [ $YT -lt $Y ] || [ $YT -eq $Y -a $MT -lt $M ] || [ $YT -eq $Y -a $MT -eq $M -a $DT -lt $D ]
    then
        echo "$line"
    else
        echo "#$line"
    fi
done < /var/teste.cfg > /tmp/teste.cfg
 
mv /tmp/teste.cfg /var/teste.cfg

This User Gave Thanks to Chubler_XL For This Post:
# 13  
Old 11-24-2012
now i have other problem

if i use this file :

Code:
#
################## User ##############
#F: net101 3320200125 1 0 0 { 0:0:1 } # 24-2-2012 ; teste #F: net102 2245604546 1 0 0 { 0:0:1 } # 24-2-2011 # F: net103 2150516516 1 0 0 { 0:0:1 } # 24-2-2013 #F: net104 2241554654 1 0 0 { 0:0:1 } # 24-2-2012 #F: net105 2102313201 1 0 0 { 0:0:1 } # 24-2-2011 #F: net106 2021202220 1 0 0 { 0:0:1 } # 24-2-2011 #F: net107 3320012335 1 0 0 { 0:0:1 } # 24-2-2010 #F: net108 1456564024 1 0 0 { 0:0:1 } # 24-2-2012 F: net109 2410456644 1 0 0 { 0:0:1 } # 24-2-2013 F: net110 6669099896 1 0 0 { 0:0:1 } # 24-2-2013 #F: net125 2021202220 1 0 0 { 0:0:1 } # 24-2-2011 #F: net254 3320012335 1 0 0 { 0:0:1 } # 25-2-2010 #F: net350 1456564024 1 0 0 { 0:0:1 } # 26-2-2012 F: net555 2410456644 1 0 0 { 0:0:1 } # 24-2-2015
################## End User ##############

after script the result is :



Code:
#
################## User ##############
#F: net101 3320200125 1 0 0 { 0:0:1 } # 24-2-2012 ; teste #F: net102 2245604546 1 0 0 { 0:0:1 } # 24-2-2011 # #F: net103 2150516516 1 0 0 { 0:0:1 } # 24-2-2013 #F: net104 2241554654 1 0 0 { 0:0:1 } # 24-2-2012 #F: net105 2102313201 1 0 0 { 0:0:1 } # 24-2-2011 #F: net106 2021202220 1 0 0 { 0:0:1 } # 24-2-2011 #F: net107 3320012335 1 0 0 { 0:0:1 } # 24-2-2010 #F: net108 1456564024 1 0 0 { 0:0:1 } # 24-2-2012 #F: net109 2410456644 1 0 0 { 0:0:1 } # 24-2-2013 #F: net110 6669099896 1 0 0 { 0:0:1 } # 24-2-2013 #F: net125 2021202220 1 0 0 { 0:0:1 } # 24-2-2011 #F: net254 3320012335 1 0 0 { 0:0:1 } # 25-2-2010 #F: net350 1456564024 1 0 0 { 0:0:1 } # 26-2-2012 #F: net555 2410456644 1 0 0 { 0:0:1 } # 24-2-2015
################## End User ##############

what is the problem please

---------- Post updated at 02:00 PM ---------- Previous update was at 01:58 PM ----------

now i have other problem

if i use this file :

Code:
#
################## User ##############
#F: net101 3320200125 1 0 0 { 0:0:1 } # 24-2-2012 ; teste #F: net102 2245604546 1 0 0 { 0:0:1 } # 24-2-2011 # F: net103 2150516516 1 0 0 { 0:0:1 } # 24-2-2013 #F: net104 2241554654 1 0 0 { 0:0:1 } # 24-2-2012 #F: net105 2102313201 1 0 0 { 0:0:1 } # 24-2-2011 #F: net106 2021202220 1 0 0 { 0:0:1 } # 24-2-2011 #F: net107 3320012335 1 0 0 { 0:0:1 } # 24-2-2010 #F: net108 1456564024 1 0 0 { 0:0:1 } # 24-2-2012 F: net109 2410456644 1 0 0 { 0:0:1 } # 24-2-2013 F: net110 6669099896 1 0 0 { 0:0:1 } # 24-2-2013 #F: net125 2021202220 1 0 0 { 0:0:1 } # 24-2-2011 #F: net254 3320012335 1 0 0 { 0:0:1 } # 25-2-2010 #F: net350 1456564024 1 0 0 { 0:0:1 } # 26-2-2012 F: net555 2410456644 1 0 0 { 0:0:1 } # 24-2-2015
################## End User ##############

after script the result is :




Code:
#
################## User ##############
#F: net101 3320200125 1 0 0 { 0:0:1 } # 24-2-2012 ; teste #F: net102 2245604546 1 0 0 { 0:0:1 } # 24-2-2011 # #F: net103 2150516516 1 0 0 { 0:0:1 } # 24-2-2013 #F: net104 2241554654 1 0 0 { 0:0:1 } # 24-2-2012 #F: net105 2102313201 1 0 0 { 0:0:1 } # 24-2-2011 #F: net106 2021202220 1 0 0 { 0:0:1 } # 24-2-2011 #F: net107 3320012335 1 0 0 { 0:0:1 } # 24-2-2010 #F: net108 1456564024 1 0 0 { 0:0:1 } # 24-2-2012 #F: net109 2410456644 1 0 0 { 0:0:1 } # 24-2-2013 #F: net110 6669099896 1 0 0 { 0:0:1 } # 24-2-2013 #F: net125 2021202220 1 0 0 { 0:0:1 } # 24-2-2011 #F: net254 3320012335 1 0 0 { 0:0:1 } # 25-2-2010 #F: net350 1456564024 1 0 0 { 0:0:1 } # 26-2-2012 #F: net555 2410456644 1 0 0 { 0:0:1 } # 24-2-2015
################## End User ##############



what is the problem please

Last edited by Scott; 11-25-2012 at 08:02 PM.. Reason: Code tags
# 14  
Old 11-25-2012
I can't see what the issue is as the format has been changed,
you need to use code tags, put [code] before your output and [/code] after (see note against post #5 in this thread).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

“sed” replace date in text file with current date

We want to call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below: abc.txt ------------------ Code: line1 line2 line3 $$EDWS_DATE_INSERT=08-27-2019 line4 $$EDWS_PREV_DATE_INSERT=08-26-2019 I am trying to write a... (3 Replies)
Discussion started by: pradeepp
3 Replies

2. Shell Programming and Scripting

Script to determine Date,TotalFile,total size of file based on date

I have file listed like below -rw-r--r--+ 1 test test 17M Nov 26 14:43 test1.gz -rw-r--r--+ 1 test test 0 Nov 26 14:44 test2.gz -rw-r--r--+ 1 test test 0 Nov 27 10:41 test3.gz -rw-r--r--+ 1 test test 244K Nov 27 10:41 test4.gz -rw-r--r--+ 1 test test 17M Nov 27 10:41 test5.gz I... (5 Replies)
Discussion started by: krish2014
5 Replies

3. UNIX for Dummies Questions & Answers

How to pick the latest file with date as one among the file name.( not exactly present date.)?

i have files like 1)20131112_abc_01.csv and 2)20131113_abc_01.csv and 3)20131113_abc_02.csv when i try to fetch the file in the next day. it shud pick the third file.. plz help me.. and i use `date +"%Y%m%d"` command to fetch..it fetches the current date... (2 Replies)
Discussion started by: applepie
2 Replies

4. Shell Programming and Scripting

Searching for unknown date inside the file and replace to new date

Hello, Iam a newbies to Shell scripting. Iam trying to replace the date inside the file to new date. is there anyway that we can just use the pattern to search as "..." I have many files want to replace with the same date, and each file contains different date. Thanks for your help. ... (2 Replies)
Discussion started by: Daro
2 Replies

5. Shell Programming and Scripting

finding date numeral from file and check the validity of date format

hi there I have file names in different format as below triss_20111117_fxcb.csv triss_fxcb_20111117.csv xpnl_hypo_reu_miplvdone_11172011.csv xpnl_hypo_reu_miplvdone_11-17-2011.csv xpnl_hypo_reu_miplvdone_20111117.csv xpnl_hypo_reu_miplvdone_20111117xfb.csv... (10 Replies)
Discussion started by: manas_ranjan
10 Replies

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

7. UNIX for Dummies Questions & Answers

Delete a row from a file if one column containing a date is greater than the current system date

Hello gurus, I am hoping someone can help me with the required code/script to make this work. I have the following file with records starting at line 4: NETW~US60~000000000013220694~002~~IT~USD~2.24~20110201~99991231~01~01~20101104~... (4 Replies)
Discussion started by: chumsky
4 Replies

8. Shell Programming and Scripting

finding the previous day date and creating a file with date

Hi guys, I had a scenario... 1. I had to get the previous days date in yyyymmdd format 2. i had to create a file with Date inthe format yyyymmdd.txt format both are different thanks guys in advance.. (4 Replies)
Discussion started by: apple2685
4 Replies

9. UNIX for Dummies Questions & Answers

Move A File With Same Date,don't Change The Desitination Dir Date

Assume, I created one file three years back and I like to move the file to some other directory with the old date (Creation date)? Is it possible? Explain? (1 Reply)
Discussion started by: jee.ku2
1 Replies

10. UNIX for Dummies Questions & Answers

Changing Creation Date to a Prespecified Date of a File In Unix

Dear Expert, Is there a command to do that in Unix? In such a way that we don't need to actually "write" or modified the content. -- monkfan (4 Replies)
Discussion started by: monkfan
4 Replies
Login or Register to Ask a Question