Bash comparing date


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Bash comparing date
# 1  
Old 07-12-2006
Bash comparing date

Cound anyone help me on how to compare date in Unix using if function on bash file?

current=date

if ["$current" = 7/12/06] ###syntax is wrong, could anyone correct it for me
then
rm -rf /usr/local/src
fi

Thank You...
# 2  
Old 07-12-2006
Can anyone give me the syntax for the date to be recognize as date:[yyyy-mm-d]?
# 3  
Old 07-12-2006
Quote:
Originally Posted by Stanford Co
Cound anyone help me on how to compare date in Unix using if function on bash file?

current=date

if ["$current" = 7/12/06] ###syntax is wrong, could anyone correct it for me
then
rm -rf /usr/local/src
fi

Thank You...
Notice the whitespace.

Code:
if [ "$current" = "7/12/06" ] ; then
rm -rf /usr/local/src
fi

# 4  
Old 07-12-2006
it still doesn't work. date:command not found.

#!/bin/sh

current=date
if ["$current" = "7/12/06"]
then
echo "test"
fi
# 5  
Old 07-12-2006
it worked!!! I just need to put the white spacing.. Thank You
# 6  
Old 07-12-2006
the bash file worked with no error. But its not comparing the date i wanted it to be executed. Please help. Thank You.
# 7  
Old 07-12-2006
There are plenty posts about date comparison on this forum, try to search first
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How bash treats literal date value and retrieve year, month and date?

Hi, I am trying to add few (say 3 days) to sysdate using - date -d '+ 3 days' +%y%m%d and it works as expected. But how to add few (say 3 days) to a literal date value and how bash treats a literal value as a date. Can we say just like in ORACLE TO_DATE that my given literal date value... (2 Replies)
Discussion started by: pointers1234
2 Replies

2. Shell Programming and Scripting

Comparing files by date/time

I am trying to compare identically named files in different directories and replace a file only with a newer version. Is there a way of doing this? TIA (4 Replies)
Discussion started by: wbport
4 Replies

3. UNIX for Dummies Questions & Answers

Comparing Output Date to Current System Date

Hi Guys, Anyone who knows how to compare the current date with the a file containing a date, say for example I have a file that looks like this: Command was launched from partition 0. ------------------------------------------------ Executing command in server server6 Fri Dec 16... (7 Replies)
Discussion started by: rymnd_12345
7 Replies

4. Shell Programming and Scripting

Need help in Shell Script comparing todays date with Yesterday date from Sysdate

Hi, I want to compare today's date(DDMMYYYY) with yesterday(DDMMYYYY) from system date,if (today month = yesterday month) then execute alter query else do nothing. The above requirement i want in Shell script(KSH)... Can any one please help me? Double post, continued here. (0 Replies)
Discussion started by: kumarmsk1331
0 Replies

5. Shell Programming and Scripting

Comparing time is bash

Hi, I have a question on comparing time using bash. Tried searching a lot up but couldn't figure it out. So I have this: CURRENT_TIME=$(date +%H:%M) if then echo "Continue" else echo "Quit" fi I tried a lot of different combinations of comparing, but nothing seems to work. Any help... (2 Replies)
Discussion started by: r4v3n
2 Replies

6. Shell Programming and Scripting

Comparing current date

Hi, I have start date and end date in the following format. I need to check the current date is greater than the start date and less than the end date. if i use the command date --date "Tue 6:00 AM", it takes next Tues day not the current week's Tues day. Is there a way to get the current Tues... (9 Replies)
Discussion started by: bharathappriyan
9 Replies

7. Homework & Coursework Questions

Date comparison with 'string date having slashes and time zone' in Bash only

1. The problem statement, all variables and given/known data: I have standard web server log file. It contains different columns (like IP address, request result code, request type etc) including a date column with the format . I have developed a log analysis command line utility that displays... (1 Reply)
Discussion started by: TariqYousaf
1 Replies

8. Linux

Comparing the file drop date with todays date

Daily one file will dropped into this directory. Directory: /opt/app/jt/drop File name: XXXX_<timestamp>.dat.gz I need to write a script which checks whether the file is dropped daily or not. Any idea in the script how can we compare timestamp of the file to today's date?? (3 Replies)
Discussion started by: Rajneel
3 Replies

9. Shell Programming and Scripting

Comparing to Date

Hi , I need to compare the given date with the system date . can you tell me any way , how to do it. The given date format is "23-AUG-2008". I need to compare it with the system time , i have got the system time in the same format by using the command "date +%e-%b-%y" ,its giving the date... (3 Replies)
Discussion started by: amit_kv1983
3 Replies

10. Shell Programming and Scripting

Perl: Extracting date from file name and comparing with current date

I need to extract the date part from the file name (20080221 in this ex) and compare it with the current date and delete it, if it is a past date. $file = exp_ABCD4_T-2584780_upto_20080221.dmp.Z really appreciate any help. thanks mkneni (4 Replies)
Discussion started by: MKNENI
4 Replies
Login or Register to Ask a Question