Shell file if condition setting start and end dates


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell file if condition setting start and end dates
# 1  
Old 04-24-2016
Shell file if condition setting start and end dates

I have shell file that has the following logic, i am new to shell programming.
What does process month $1 do?

I am assuming that the below dates go back three months from sysdate month. is it right :


Code:
curr_month=`date +%Y%m`
Beg_o_time=`date -d "2012/03/01" +%Y%m`
Process_months=$1
Parallel_groups=$2
PROCESS_DIR=/usr/local/bin/TPThadoop

###  Resolve stop time should be one month past
if [ -z $Process_months ]
then
process_end=$Beg_o_time
else
process_end=`date -d "-$Process_months months" +%Y%m`
fi


Thanks a lot for the helpful info.

Last edited by Don Cragun; 04-24-2016 at 08:59 PM.. Reason: Add CODE and ICODE tags.
# 2  
Old 04-25-2016
Quote:
Originally Posted by cplusplus1
I have shell file that has the following logic, i am new to shell programming.
What does process month $1 do?

I am assuming that the below dates go back three months from sysdate month. is it right :


Code:
curr_month=`date +%Y%m`
Beg_o_time=`date -d "2012/03/01" +%Y%m`
Process_months=$1
Parallel_groups=$2
PROCESS_DIR=/usr/local/bin/TPThadoop

###  Resolve stop time should be one month past
if [ -z $Process_months ]
then
process_end=$Beg_o_time
else
process_end=`date -d "-$Process_months months" +%Y%m`
fi


Thanks a lot for the helpful info.
No, or maybe. It depends on the parameters that you pass to this script when you invoke it. And, of course it also depends on what locale you are using (Is "2012/03/01" March 1st or January 3rd?), what shell you are using (Process_months=$1 is a syntax error in csh and its derivatives, but sets the shell variable Process_months to the string specified by the 1st parameter passed to this script when you invoked it in a shell that uses Bourne shell syntax), and on what operating system you're using (date -d is an unknown option on some system and a means to specify a date and/or time other than the current date and time if you're using date on other operating systems).

Assuming that you are using a shell based on Bourne shell syntax, that you are using an operating system that comes with a GNU version of the date utility, and that you invoke this script with a 1st command line parameter set to 3, then the shell variable process_end will be set to a string that is the complete year number followed by the month number (as a two-digit decimal value with a leading zero if the month represented comes before October) for a date that is three months before you run this script.

Since what you have shown us gives no indication of what will be done with that variable, I have absolutely no idea whether or not that means that the script will process "dates" that "go back three months from sysdate month".

No matter what shell you are using, the test being used in the if statement:
Code:
if [ -z $Process_months ]
then
process_end=$Beg_o_time
else
process_end=`date -d "-$Process_months months" +%Y%m`
fi

is incorrectly specified, but (on a shell using Bourne shell syntax) will accidentally do what was wanted if no command line arguments were specified when the script was invoked. In this case the test will evaluate as true because the string -z is not an empty string while the code seems to have been written to determine whether or not the expansion of the 1st command-line parameter was an empty string which would have been correctly written as:
Code:
[ -z "$Process_months" ]

I hope this helps.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Splitting week start date and end date based on custom period start dates

Below are my custom period start and end dates based on a calender, these dates are placed in a file, for each period i need to split into three weeks for each period row, example is given below. Could you please help out to achieve solution through shell script.. File content: ... (2 Replies)
Discussion started by: nani2019
2 Replies

2. Shell Programming and Scripting

Search a String between start and end of a block in a file

Hi, I have a scenario where I want to display the output based on the pattern search between the start and end of a block in a file, we can have multiple start and end blocks in a file. Example give below, we need to search between the start block abc and end block def in a file, after that... (5 Replies)
Discussion started by: G.K.K
5 Replies

3. Shell Programming and Scripting

Split a file by start and end row.

I have a file which looks something as following, I would like to split to several files, The start and end of each file is 'FILE' and end with 'ASCII... ' . At the same time for each file in the first column add 100 and also second column add 100 the rest of the column as it is , see example of... (2 Replies)
Discussion started by: tk2000
2 Replies

4. Shell Programming and Scripting

How to extract start/end times from log file to CSV file?

Hi, I have a log file (log.txt) that which contains lines of date/time. I need to create a script to extract a CSV file (out.csv) that gets all the sequential times (with only 1 minute difference) together by stating the start time and end time of this period. Sample log file (log.txt) ... (7 Replies)
Discussion started by: Mr.Zizo
7 Replies

5. Shell Programming and Scripting

Grep start and end line of each segments in a file

Cat file1 -------- ---------- SCHEMA.TABLE1 insert------- update----- ------------- ---------- SCHEMA.TABLE2 insert------- update----- ----------- ------------ SCHEMA.TABLE3 insert------- update----- ------------ grep -n SCHEMA > header_file2.txt (2 Replies)
Discussion started by: Veera_V
2 Replies

6. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

7. UNIX for Dummies Questions & Answers

Find Quarter Start and End Dates

Dear Members, Depending on the current date i should find out the start and end dates of the quarter. ex: Today date is 14-Nov-2011 then Quarter start date should be Oct 1 2011 and Quarter End date should be Dec 31 2011. How can i do this? Thanks Sandeep (1 Reply)
Discussion started by: sandeep_1105
1 Replies

8. Shell Programming and Scripting

Need to capture dates between start date and end date Using perl.

Hi All, Want to get all dates and Julian week number for that date between the start date and end date. How can I achive this using perl? (To achive above functionality, I was connecting to the database from DB server. Need to execute the same script in application server, since databse... (6 Replies)
Discussion started by: Nagaraja Akkiva
6 Replies

9. Shell Programming and Scripting

Need to capture all dates between start date and End date.

Hi All, I enter Start date and end date as parameters. I need to capture dates between start date and end date. Please let me know if you have any idea the same. Thanks in advance. Nagaraja Akkivalli. (5 Replies)
Discussion started by: Nagaraja Akkiva
5 Replies

10. Shell Programming and Scripting

remove XML parent start and end tags in same file

Hi All, Requirement: remove start and end tag of parent element <DummyLevel> <level1> </level1> <level2> </level2> <level3> </level3> <level4> </level4> <level5> </level5> <level6> </level7> </DummyLevel> I have to delete the first <dummylevel> and last </DummyLevel> tags from... (7 Replies)
Discussion started by: dstage2006
7 Replies
Login or Register to Ask a Question