Shell script issue on date and day


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script issue on date and day
# 1  
Old 03-31-2014
Shell script issue on date and day

Hi friends,

I wanna check if any given date is Friday, as an example I have written a simple script as shown below

Code:
 
#!/bin/ksh
v_date=20140325
if [ $($v_date +%a) == "Fri" ] ; then
echo 'HELLO'
else
echo 'BYE'
fi

But when I am executing its throwing an error as shown below,

Code:
 
+ v_date=20140325
+ 20140325 +%a
simple.sh[5]: 20140325:  not found.
+ [ == Fri ]
simple.sh[5]: test: 0403-004 Specify a parameter with this command.


Any help is much appreciated!!
# 2  
Old 03-31-2014
You're trying to 'run' a date, which is not executable. You could try this depending on your OS and version of date:
Code:
date --date="20140325" +%a

# 3  
Old 03-31-2014
That error message looks like it's from AIX, in which case -d option of date will not be supported.

You could use perl eg:

Code:
dow=$( echo "20140325" | perl -ne 'use POSIX qw(strftime);use Time::Local; /(....)(..)(..)/;  print strftime("%u",localtime(timelocal(0,0,0,$3,$2 - 1, $1)));' )
if [ $dow -eq 5 ]
then
   echo 'HELLO'
else
    echo 'BYE'
fi

# 4  
Old 03-31-2014
Ok Champs thanks very much for your help!! its really much appreciated
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace date in file every day with current date

I Have text like XXX_20190908.csv.gz need to replace Only date in this format with current date every day Thanks! (1 Reply)
Discussion started by: yamasani1991
1 Replies

2. Shell Programming and Scripting

How to check day name is it saturday in bash shell script?

How to check the day name,is it saturday in bash shell script. If dayname = saturday then run the full load else run just the incremental loads end if Thank you very much for the helpful information. (4 Replies)
Discussion started by: cplusplus1
4 Replies

3. Shell Programming and Scripting

How to get the consecutive last 10 week day date using UNIX ksh shell scripting?

Hi, i am writing a ksh shell script to check the last month end date whether it is falling in last 10 week day date, I am not sure How to use "Mr. Perderabo's date calculator", Could you Please let me know how to use to get my requirement, I tried my own script but duplicate week day and... (5 Replies)
Discussion started by: karthikram
5 Replies

4. Shell Programming and Scripting

How to find the date of previous day in shell script?

Hi Experts, i am using the below code get the date of previous day. #!/usr/bin/ksh datestamp=`date '+%Y%m%d'` yest=$((datestamp -1)) echo $yest When i execute the code i am getting output as: 20130715 What i am trying here is, based on the date passed i am fetching previus day's... (0 Replies)
Discussion started by: learner24
0 Replies

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

6. Shell Programming and Scripting

how to obtain date and day of the week from `date` command

Hi, does anybody know how to format `date` command correctly to return the day of the week? Thanks -A I work in ksh.... (1 Reply)
Discussion started by: aoussenko
1 Replies

7. Shell Programming and Scripting

Find out the day in Bash Shell script

Hello All, I need a bash shell script to find out a day from the date.For example we give the date(20100227/YYYYMMDD) then we get the day 'Saturday'. Thanks in advance, Satheesh (5 Replies)
Discussion started by: satheesh4093
5 Replies

8. Shell Programming and Scripting

How to increment a user defined date value in the DATE format itself using shell script?

I need to increment a date value through shell script. Input value consist of start date and end date in DATE format of unix. For eg. I need increment a date value of 1/1/09 to 31/12/09 i.e for a whole yr. The output must look like 1/1/09 2/2/09 . . . 31/1/09 . . 1/2/09 . 28/2/09... (1 Reply)
Discussion started by: sunil087
1 Replies

9. Shell Programming and Scripting

Date increment issue due to day light saving

The date increment worked fine until date reached 25/10, which is DLS change date. /bin/date --date="091025 1 day" +%y%m%d; the output is 091025 Is this a bug or something missing from the code ! (3 Replies)
Discussion started by: rajbravo
3 Replies

10. Shell Programming and Scripting

Write a shell script to find whether the first day of the month is a working day

Hi , I am relatively new to unix... Can u pls help me out to find out if the first day of the month is a working day ie from (Monday to Friday)...using Date and If clause in Korn shell.. This is very urgent. Thanks for ur help... (7 Replies)
Discussion started by: phani
7 Replies
Login or Register to Ask a Question