How do I generate multiple reports? I'm only getting the daily report right now
Clash Royale CLAN TAG#URR8PPP
#!/bin/bash
#--------------------------------------------------------------------------
daily="FILE_PATH/Daily"
weekly="/FILE_PATH/Weekly"
semianually="/FILE_PATH/SemiAnnually"
_endDate=$(date +"%m%d%Y")
_day=$(date +"%u")
if [ $_day -ge 1 ] || [ $_day -le 7 ]
then
backNumDays="180"
directory=$semianually
_beginDate=$(date -d "183 days ago" +"%m%d%Y")
report="$_beginDate-$_endDate"SemiAnnualReport".csv"
else
:
fi
if [ $_day -ge 1 ] || [ $_day -le 7 ]
then
backNumDays="7"
directory=$weekly
_beginDate=$(date -d "7 days ago" +"%m%d%Y")
report="$_beginDate-$_endDate"WeeklyReport".csv"
else
:
fi
if [ $_day -ge 1 ] || [ $_day -le 7 ]
then
backNumDays="1"
directory=$daily
_beginDate=$(date -d "1 day ago" +"%m%d%Y")
report="$_beginDate-$_endDate"DailyReport".csv"
fi
#_____sql query_______
exec_file_Report()
status=`/SIDS/app/oracle/product/12.1.0.2/client/bin/sqlplus -S << +++
$DB_CONNECT
--
SET head on
SET feedback OFF
SET pagesize 10000
SET linesize 2000;
SET colsep ,
set trimspool on
set trimout on
set trims on
set UNDERLINE OFF
set verify off
set echo off
set term off
spool "$directory/$report"
SELECT * FROM TABLE_NAME WHERE rownum <= $backNumDays
;
spool off
exit
+++
`
exec_file_Report
I can not figure out why a daily report is being generated. The cron is setup to run: Everyday for daily, Sunday for weekly and last day of month for semiannual. The reason all my ifs are using the same parameters it simply to test my code in the event multiple conditions occur such as Sunday also being the last day of the month.
shell-script shell
add a comment |
#!/bin/bash
#--------------------------------------------------------------------------
daily="FILE_PATH/Daily"
weekly="/FILE_PATH/Weekly"
semianually="/FILE_PATH/SemiAnnually"
_endDate=$(date +"%m%d%Y")
_day=$(date +"%u")
if [ $_day -ge 1 ] || [ $_day -le 7 ]
then
backNumDays="180"
directory=$semianually
_beginDate=$(date -d "183 days ago" +"%m%d%Y")
report="$_beginDate-$_endDate"SemiAnnualReport".csv"
else
:
fi
if [ $_day -ge 1 ] || [ $_day -le 7 ]
then
backNumDays="7"
directory=$weekly
_beginDate=$(date -d "7 days ago" +"%m%d%Y")
report="$_beginDate-$_endDate"WeeklyReport".csv"
else
:
fi
if [ $_day -ge 1 ] || [ $_day -le 7 ]
then
backNumDays="1"
directory=$daily
_beginDate=$(date -d "1 day ago" +"%m%d%Y")
report="$_beginDate-$_endDate"DailyReport".csv"
fi
#_____sql query_______
exec_file_Report()
status=`/SIDS/app/oracle/product/12.1.0.2/client/bin/sqlplus -S << +++
$DB_CONNECT
--
SET head on
SET feedback OFF
SET pagesize 10000
SET linesize 2000;
SET colsep ,
set trimspool on
set trimout on
set trims on
set UNDERLINE OFF
set verify off
set echo off
set term off
spool "$directory/$report"
SELECT * FROM TABLE_NAME WHERE rownum <= $backNumDays
;
spool off
exit
+++
`
exec_file_Report
I can not figure out why a daily report is being generated. The cron is setup to run: Everyday for daily, Sunday for weekly and last day of month for semiannual. The reason all my ifs are using the same parameters it simply to test my code in the event multiple conditions occur such as Sunday also being the last day of the month.
shell-script shell
Can you try to explain this a little more clearly? Like, what do you want to happen? Why are you testingif [ $_day -ge 1 ] || [ $_day -le 7 ]
? Isn’t that always true? Are you just running this script 429 (365+52+12) times per year? Is this your “real” code, or just a dummy test version? … … … … … … … … … … … … … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete.
– G-Man
Feb 8 at 1:29
This is currently a test version because I want them all to be true thus, generate all 3 reports. This is to see if days like March 31st which is the last day of month and a Sunday, will generate a report for both Weekly (Sunday) and semiannual (last day of month).
– Chris Tran
Feb 8 at 1:38
add a comment |
#!/bin/bash
#--------------------------------------------------------------------------
daily="FILE_PATH/Daily"
weekly="/FILE_PATH/Weekly"
semianually="/FILE_PATH/SemiAnnually"
_endDate=$(date +"%m%d%Y")
_day=$(date +"%u")
if [ $_day -ge 1 ] || [ $_day -le 7 ]
then
backNumDays="180"
directory=$semianually
_beginDate=$(date -d "183 days ago" +"%m%d%Y")
report="$_beginDate-$_endDate"SemiAnnualReport".csv"
else
:
fi
if [ $_day -ge 1 ] || [ $_day -le 7 ]
then
backNumDays="7"
directory=$weekly
_beginDate=$(date -d "7 days ago" +"%m%d%Y")
report="$_beginDate-$_endDate"WeeklyReport".csv"
else
:
fi
if [ $_day -ge 1 ] || [ $_day -le 7 ]
then
backNumDays="1"
directory=$daily
_beginDate=$(date -d "1 day ago" +"%m%d%Y")
report="$_beginDate-$_endDate"DailyReport".csv"
fi
#_____sql query_______
exec_file_Report()
status=`/SIDS/app/oracle/product/12.1.0.2/client/bin/sqlplus -S << +++
$DB_CONNECT
--
SET head on
SET feedback OFF
SET pagesize 10000
SET linesize 2000;
SET colsep ,
set trimspool on
set trimout on
set trims on
set UNDERLINE OFF
set verify off
set echo off
set term off
spool "$directory/$report"
SELECT * FROM TABLE_NAME WHERE rownum <= $backNumDays
;
spool off
exit
+++
`
exec_file_Report
I can not figure out why a daily report is being generated. The cron is setup to run: Everyday for daily, Sunday for weekly and last day of month for semiannual. The reason all my ifs are using the same parameters it simply to test my code in the event multiple conditions occur such as Sunday also being the last day of the month.
shell-script shell
#!/bin/bash
#--------------------------------------------------------------------------
daily="FILE_PATH/Daily"
weekly="/FILE_PATH/Weekly"
semianually="/FILE_PATH/SemiAnnually"
_endDate=$(date +"%m%d%Y")
_day=$(date +"%u")
if [ $_day -ge 1 ] || [ $_day -le 7 ]
then
backNumDays="180"
directory=$semianually
_beginDate=$(date -d "183 days ago" +"%m%d%Y")
report="$_beginDate-$_endDate"SemiAnnualReport".csv"
else
:
fi
if [ $_day -ge 1 ] || [ $_day -le 7 ]
then
backNumDays="7"
directory=$weekly
_beginDate=$(date -d "7 days ago" +"%m%d%Y")
report="$_beginDate-$_endDate"WeeklyReport".csv"
else
:
fi
if [ $_day -ge 1 ] || [ $_day -le 7 ]
then
backNumDays="1"
directory=$daily
_beginDate=$(date -d "1 day ago" +"%m%d%Y")
report="$_beginDate-$_endDate"DailyReport".csv"
fi
#_____sql query_______
exec_file_Report()
status=`/SIDS/app/oracle/product/12.1.0.2/client/bin/sqlplus -S << +++
$DB_CONNECT
--
SET head on
SET feedback OFF
SET pagesize 10000
SET linesize 2000;
SET colsep ,
set trimspool on
set trimout on
set trims on
set UNDERLINE OFF
set verify off
set echo off
set term off
spool "$directory/$report"
SELECT * FROM TABLE_NAME WHERE rownum <= $backNumDays
;
spool off
exit
+++
`
exec_file_Report
I can not figure out why a daily report is being generated. The cron is setup to run: Everyday for daily, Sunday for weekly and last day of month for semiannual. The reason all my ifs are using the same parameters it simply to test my code in the event multiple conditions occur such as Sunday also being the last day of the month.
shell-script shell
shell-script shell
asked Feb 8 at 0:59
Chris TranChris Tran
32
32
Can you try to explain this a little more clearly? Like, what do you want to happen? Why are you testingif [ $_day -ge 1 ] || [ $_day -le 7 ]
? Isn’t that always true? Are you just running this script 429 (365+52+12) times per year? Is this your “real” code, or just a dummy test version? … … … … … … … … … … … … … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete.
– G-Man
Feb 8 at 1:29
This is currently a test version because I want them all to be true thus, generate all 3 reports. This is to see if days like March 31st which is the last day of month and a Sunday, will generate a report for both Weekly (Sunday) and semiannual (last day of month).
– Chris Tran
Feb 8 at 1:38
add a comment |
Can you try to explain this a little more clearly? Like, what do you want to happen? Why are you testingif [ $_day -ge 1 ] || [ $_day -le 7 ]
? Isn’t that always true? Are you just running this script 429 (365+52+12) times per year? Is this your “real” code, or just a dummy test version? … … … … … … … … … … … … … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete.
– G-Man
Feb 8 at 1:29
This is currently a test version because I want them all to be true thus, generate all 3 reports. This is to see if days like March 31st which is the last day of month and a Sunday, will generate a report for both Weekly (Sunday) and semiannual (last day of month).
– Chris Tran
Feb 8 at 1:38
Can you try to explain this a little more clearly? Like, what do you want to happen? Why are you testing
if [ $_day -ge 1 ] || [ $_day -le 7 ]
? Isn’t that always true? Are you just running this script 429 (365+52+12) times per year? Is this your “real” code, or just a dummy test version? … … … … … … … … … … … … … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete.– G-Man
Feb 8 at 1:29
Can you try to explain this a little more clearly? Like, what do you want to happen? Why are you testing
if [ $_day -ge 1 ] || [ $_day -le 7 ]
? Isn’t that always true? Are you just running this script 429 (365+52+12) times per year? Is this your “real” code, or just a dummy test version? … … … … … … … … … … … … … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete.– G-Man
Feb 8 at 1:29
This is currently a test version because I want them all to be true thus, generate all 3 reports. This is to see if days like March 31st which is the last day of month and a Sunday, will generate a report for both Weekly (Sunday) and semiannual (last day of month).
– Chris Tran
Feb 8 at 1:38
This is currently a test version because I want them all to be true thus, generate all 3 reports. This is to see if days like March 31st which is the last day of month and a Sunday, will generate a report for both Weekly (Sunday) and semiannual (last day of month).
– Chris Tran
Feb 8 at 1:38
add a comment |
1 Answer
1
active
oldest
votes
Perhaps I’m missing something,
but I guess you want (this test version of) your script
to generate all three reports every time you run it.
But the script just isn’t set up
to generate multiple reports in a single invocation.
The general flow of what happens when you run the script is
if (condition that’s always true)
then
backNumDays="180"
directory="$semiannually"
︙
else
:
fi
if (condition that’s always true)
then
backNumDays="7"
directory="$weekly"
︙
else
:
fi
if (condition that’s always true)
then
backNumDays="1"
directory="$daily"
︙
fi
(Generate daily report)
You need to do something like
(define exec_file_Report function)
if (it’s the last day of the month)
then
backNumDays="180"
directory="$semiannually"
︙
exec_file_Report
fi
if (it’s Sunday)
then
backNumDays="7"
directory="$weekly"
︙
exec_file_Report
fi
backNumDays="1"
directory="$daily"
︙
exec_file_Report
This script can generate all three reports in a single invocation.
For example, on February 10, February 17, February 24,
March 3, March 10, March 17 and March 24 (all of which are Sundays),
it will do the monthly report and the daily report.
On February 28 it will do the semiannual report and the daily report.
On Sunday March 31 it will do all three.
So you only need to run the script every day;
you don’t need the three cron lines.
Now you’re saying that, on any of the above multiple-report days,
you want the daily report to be generated at 2 PM
and the other(s) at 11:59 PM.
This is the sort of detail
that should have been included in the question
when I asked for clarification.
To handle this, you must make the script either smarter or less smart.
I recommend making it less smart.
Change it, not to figure out for itself what report(s) to generate,
but to take an argument telling it which report to generate.
Something like this:
(define exec_file_Report function)
case "$1" in
(semiannual)
backNumDays="180"
directory="$semiannually"
︙
exec_file_Report
;;
(weekly)
backNumDays="7"
directory="$weekly"
︙
exec_file_Report
;;
(daily)
backNumDays="1"
directory="$daily"
︙
exec_file_Report
;;
esac
And then keep the crontab entries you have now, but add the arguments:
0 14 * * * /path/to/your/script daily
59 23 * * 0 /path/to/your/script weekly
59 23 (last) * * /path/to/your/script semiannual
Ummm — how are you using cron to run a job on the last day of the month?
Warning: I have not tested the above.
Notes:
- There’s no reason to do
else :
. - There’s no reason to use an
if
to test a condition that’s always true
to handle code that you want to execute every time. exec
is the name of a Unix system function and a shell command.
Using it as part of the name of a function is confusing.
My plan is to set up 3 cron jobs because these will be required to run at certain times. Here is how I have it setup currently: Daily - everyday at 2PM Weekly - every Sunday at 11:59PM SemiAnnually - every last day of the month at 11:59PM Sorry I'm really new to scripting and I really appreciate your insight. I figured since it will run on 3 different occasions, it will go through the if statements to determine what file needs to be generated. My concern are the days like March 31st which will be a Sunday and the last day of the month.
– Chris Tran
Feb 8 at 2:18
For the last days of the month I'm just doing something like: 55 23 31 1,3,5,7,8,10,12 *
– Chris Tran
Feb 8 at 13:05
Sorry I'm just a little confused. So I'm defining the exec_file_Report function before the cases and calling then calling the function in each of the cases but not getting a report at all now. I tried doing it this way but using my if conditions but I get an TNS error when manually running.
– Chris Tran
Feb 8 at 13:48
Hey I just want to say thank you! I used cases previously but just tried passing the "day" as an argument. I'm really new to all this and your post really helped guide me to the answer. I will post an update on how I achieved this with your insight when I get back home. Again, thank you!!
– Chris Tran
Feb 8 at 14:36
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f499385%2fhow-do-i-generate-multiple-reports-im-only-getting-the-daily-report-right-now%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Perhaps I’m missing something,
but I guess you want (this test version of) your script
to generate all three reports every time you run it.
But the script just isn’t set up
to generate multiple reports in a single invocation.
The general flow of what happens when you run the script is
if (condition that’s always true)
then
backNumDays="180"
directory="$semiannually"
︙
else
:
fi
if (condition that’s always true)
then
backNumDays="7"
directory="$weekly"
︙
else
:
fi
if (condition that’s always true)
then
backNumDays="1"
directory="$daily"
︙
fi
(Generate daily report)
You need to do something like
(define exec_file_Report function)
if (it’s the last day of the month)
then
backNumDays="180"
directory="$semiannually"
︙
exec_file_Report
fi
if (it’s Sunday)
then
backNumDays="7"
directory="$weekly"
︙
exec_file_Report
fi
backNumDays="1"
directory="$daily"
︙
exec_file_Report
This script can generate all three reports in a single invocation.
For example, on February 10, February 17, February 24,
March 3, March 10, March 17 and March 24 (all of which are Sundays),
it will do the monthly report and the daily report.
On February 28 it will do the semiannual report and the daily report.
On Sunday March 31 it will do all three.
So you only need to run the script every day;
you don’t need the three cron lines.
Now you’re saying that, on any of the above multiple-report days,
you want the daily report to be generated at 2 PM
and the other(s) at 11:59 PM.
This is the sort of detail
that should have been included in the question
when I asked for clarification.
To handle this, you must make the script either smarter or less smart.
I recommend making it less smart.
Change it, not to figure out for itself what report(s) to generate,
but to take an argument telling it which report to generate.
Something like this:
(define exec_file_Report function)
case "$1" in
(semiannual)
backNumDays="180"
directory="$semiannually"
︙
exec_file_Report
;;
(weekly)
backNumDays="7"
directory="$weekly"
︙
exec_file_Report
;;
(daily)
backNumDays="1"
directory="$daily"
︙
exec_file_Report
;;
esac
And then keep the crontab entries you have now, but add the arguments:
0 14 * * * /path/to/your/script daily
59 23 * * 0 /path/to/your/script weekly
59 23 (last) * * /path/to/your/script semiannual
Ummm — how are you using cron to run a job on the last day of the month?
Warning: I have not tested the above.
Notes:
- There’s no reason to do
else :
. - There’s no reason to use an
if
to test a condition that’s always true
to handle code that you want to execute every time. exec
is the name of a Unix system function and a shell command.
Using it as part of the name of a function is confusing.
My plan is to set up 3 cron jobs because these will be required to run at certain times. Here is how I have it setup currently: Daily - everyday at 2PM Weekly - every Sunday at 11:59PM SemiAnnually - every last day of the month at 11:59PM Sorry I'm really new to scripting and I really appreciate your insight. I figured since it will run on 3 different occasions, it will go through the if statements to determine what file needs to be generated. My concern are the days like March 31st which will be a Sunday and the last day of the month.
– Chris Tran
Feb 8 at 2:18
For the last days of the month I'm just doing something like: 55 23 31 1,3,5,7,8,10,12 *
– Chris Tran
Feb 8 at 13:05
Sorry I'm just a little confused. So I'm defining the exec_file_Report function before the cases and calling then calling the function in each of the cases but not getting a report at all now. I tried doing it this way but using my if conditions but I get an TNS error when manually running.
– Chris Tran
Feb 8 at 13:48
Hey I just want to say thank you! I used cases previously but just tried passing the "day" as an argument. I'm really new to all this and your post really helped guide me to the answer. I will post an update on how I achieved this with your insight when I get back home. Again, thank you!!
– Chris Tran
Feb 8 at 14:36
add a comment |
Perhaps I’m missing something,
but I guess you want (this test version of) your script
to generate all three reports every time you run it.
But the script just isn’t set up
to generate multiple reports in a single invocation.
The general flow of what happens when you run the script is
if (condition that’s always true)
then
backNumDays="180"
directory="$semiannually"
︙
else
:
fi
if (condition that’s always true)
then
backNumDays="7"
directory="$weekly"
︙
else
:
fi
if (condition that’s always true)
then
backNumDays="1"
directory="$daily"
︙
fi
(Generate daily report)
You need to do something like
(define exec_file_Report function)
if (it’s the last day of the month)
then
backNumDays="180"
directory="$semiannually"
︙
exec_file_Report
fi
if (it’s Sunday)
then
backNumDays="7"
directory="$weekly"
︙
exec_file_Report
fi
backNumDays="1"
directory="$daily"
︙
exec_file_Report
This script can generate all three reports in a single invocation.
For example, on February 10, February 17, February 24,
March 3, March 10, March 17 and March 24 (all of which are Sundays),
it will do the monthly report and the daily report.
On February 28 it will do the semiannual report and the daily report.
On Sunday March 31 it will do all three.
So you only need to run the script every day;
you don’t need the three cron lines.
Now you’re saying that, on any of the above multiple-report days,
you want the daily report to be generated at 2 PM
and the other(s) at 11:59 PM.
This is the sort of detail
that should have been included in the question
when I asked for clarification.
To handle this, you must make the script either smarter or less smart.
I recommend making it less smart.
Change it, not to figure out for itself what report(s) to generate,
but to take an argument telling it which report to generate.
Something like this:
(define exec_file_Report function)
case "$1" in
(semiannual)
backNumDays="180"
directory="$semiannually"
︙
exec_file_Report
;;
(weekly)
backNumDays="7"
directory="$weekly"
︙
exec_file_Report
;;
(daily)
backNumDays="1"
directory="$daily"
︙
exec_file_Report
;;
esac
And then keep the crontab entries you have now, but add the arguments:
0 14 * * * /path/to/your/script daily
59 23 * * 0 /path/to/your/script weekly
59 23 (last) * * /path/to/your/script semiannual
Ummm — how are you using cron to run a job on the last day of the month?
Warning: I have not tested the above.
Notes:
- There’s no reason to do
else :
. - There’s no reason to use an
if
to test a condition that’s always true
to handle code that you want to execute every time. exec
is the name of a Unix system function and a shell command.
Using it as part of the name of a function is confusing.
My plan is to set up 3 cron jobs because these will be required to run at certain times. Here is how I have it setup currently: Daily - everyday at 2PM Weekly - every Sunday at 11:59PM SemiAnnually - every last day of the month at 11:59PM Sorry I'm really new to scripting and I really appreciate your insight. I figured since it will run on 3 different occasions, it will go through the if statements to determine what file needs to be generated. My concern are the days like March 31st which will be a Sunday and the last day of the month.
– Chris Tran
Feb 8 at 2:18
For the last days of the month I'm just doing something like: 55 23 31 1,3,5,7,8,10,12 *
– Chris Tran
Feb 8 at 13:05
Sorry I'm just a little confused. So I'm defining the exec_file_Report function before the cases and calling then calling the function in each of the cases but not getting a report at all now. I tried doing it this way but using my if conditions but I get an TNS error when manually running.
– Chris Tran
Feb 8 at 13:48
Hey I just want to say thank you! I used cases previously but just tried passing the "day" as an argument. I'm really new to all this and your post really helped guide me to the answer. I will post an update on how I achieved this with your insight when I get back home. Again, thank you!!
– Chris Tran
Feb 8 at 14:36
add a comment |
Perhaps I’m missing something,
but I guess you want (this test version of) your script
to generate all three reports every time you run it.
But the script just isn’t set up
to generate multiple reports in a single invocation.
The general flow of what happens when you run the script is
if (condition that’s always true)
then
backNumDays="180"
directory="$semiannually"
︙
else
:
fi
if (condition that’s always true)
then
backNumDays="7"
directory="$weekly"
︙
else
:
fi
if (condition that’s always true)
then
backNumDays="1"
directory="$daily"
︙
fi
(Generate daily report)
You need to do something like
(define exec_file_Report function)
if (it’s the last day of the month)
then
backNumDays="180"
directory="$semiannually"
︙
exec_file_Report
fi
if (it’s Sunday)
then
backNumDays="7"
directory="$weekly"
︙
exec_file_Report
fi
backNumDays="1"
directory="$daily"
︙
exec_file_Report
This script can generate all three reports in a single invocation.
For example, on February 10, February 17, February 24,
March 3, March 10, March 17 and March 24 (all of which are Sundays),
it will do the monthly report and the daily report.
On February 28 it will do the semiannual report and the daily report.
On Sunday March 31 it will do all three.
So you only need to run the script every day;
you don’t need the three cron lines.
Now you’re saying that, on any of the above multiple-report days,
you want the daily report to be generated at 2 PM
and the other(s) at 11:59 PM.
This is the sort of detail
that should have been included in the question
when I asked for clarification.
To handle this, you must make the script either smarter or less smart.
I recommend making it less smart.
Change it, not to figure out for itself what report(s) to generate,
but to take an argument telling it which report to generate.
Something like this:
(define exec_file_Report function)
case "$1" in
(semiannual)
backNumDays="180"
directory="$semiannually"
︙
exec_file_Report
;;
(weekly)
backNumDays="7"
directory="$weekly"
︙
exec_file_Report
;;
(daily)
backNumDays="1"
directory="$daily"
︙
exec_file_Report
;;
esac
And then keep the crontab entries you have now, but add the arguments:
0 14 * * * /path/to/your/script daily
59 23 * * 0 /path/to/your/script weekly
59 23 (last) * * /path/to/your/script semiannual
Ummm — how are you using cron to run a job on the last day of the month?
Warning: I have not tested the above.
Notes:
- There’s no reason to do
else :
. - There’s no reason to use an
if
to test a condition that’s always true
to handle code that you want to execute every time. exec
is the name of a Unix system function and a shell command.
Using it as part of the name of a function is confusing.
Perhaps I’m missing something,
but I guess you want (this test version of) your script
to generate all three reports every time you run it.
But the script just isn’t set up
to generate multiple reports in a single invocation.
The general flow of what happens when you run the script is
if (condition that’s always true)
then
backNumDays="180"
directory="$semiannually"
︙
else
:
fi
if (condition that’s always true)
then
backNumDays="7"
directory="$weekly"
︙
else
:
fi
if (condition that’s always true)
then
backNumDays="1"
directory="$daily"
︙
fi
(Generate daily report)
You need to do something like
(define exec_file_Report function)
if (it’s the last day of the month)
then
backNumDays="180"
directory="$semiannually"
︙
exec_file_Report
fi
if (it’s Sunday)
then
backNumDays="7"
directory="$weekly"
︙
exec_file_Report
fi
backNumDays="1"
directory="$daily"
︙
exec_file_Report
This script can generate all three reports in a single invocation.
For example, on February 10, February 17, February 24,
March 3, March 10, March 17 and March 24 (all of which are Sundays),
it will do the monthly report and the daily report.
On February 28 it will do the semiannual report and the daily report.
On Sunday March 31 it will do all three.
So you only need to run the script every day;
you don’t need the three cron lines.
Now you’re saying that, on any of the above multiple-report days,
you want the daily report to be generated at 2 PM
and the other(s) at 11:59 PM.
This is the sort of detail
that should have been included in the question
when I asked for clarification.
To handle this, you must make the script either smarter or less smart.
I recommend making it less smart.
Change it, not to figure out for itself what report(s) to generate,
but to take an argument telling it which report to generate.
Something like this:
(define exec_file_Report function)
case "$1" in
(semiannual)
backNumDays="180"
directory="$semiannually"
︙
exec_file_Report
;;
(weekly)
backNumDays="7"
directory="$weekly"
︙
exec_file_Report
;;
(daily)
backNumDays="1"
directory="$daily"
︙
exec_file_Report
;;
esac
And then keep the crontab entries you have now, but add the arguments:
0 14 * * * /path/to/your/script daily
59 23 * * 0 /path/to/your/script weekly
59 23 (last) * * /path/to/your/script semiannual
Ummm — how are you using cron to run a job on the last day of the month?
Warning: I have not tested the above.
Notes:
- There’s no reason to do
else :
. - There’s no reason to use an
if
to test a condition that’s always true
to handle code that you want to execute every time. exec
is the name of a Unix system function and a shell command.
Using it as part of the name of a function is confusing.
edited Feb 8 at 4:49
answered Feb 8 at 2:02
G-ManG-Man
13.3k93566
13.3k93566
My plan is to set up 3 cron jobs because these will be required to run at certain times. Here is how I have it setup currently: Daily - everyday at 2PM Weekly - every Sunday at 11:59PM SemiAnnually - every last day of the month at 11:59PM Sorry I'm really new to scripting and I really appreciate your insight. I figured since it will run on 3 different occasions, it will go through the if statements to determine what file needs to be generated. My concern are the days like March 31st which will be a Sunday and the last day of the month.
– Chris Tran
Feb 8 at 2:18
For the last days of the month I'm just doing something like: 55 23 31 1,3,5,7,8,10,12 *
– Chris Tran
Feb 8 at 13:05
Sorry I'm just a little confused. So I'm defining the exec_file_Report function before the cases and calling then calling the function in each of the cases but not getting a report at all now. I tried doing it this way but using my if conditions but I get an TNS error when manually running.
– Chris Tran
Feb 8 at 13:48
Hey I just want to say thank you! I used cases previously but just tried passing the "day" as an argument. I'm really new to all this and your post really helped guide me to the answer. I will post an update on how I achieved this with your insight when I get back home. Again, thank you!!
– Chris Tran
Feb 8 at 14:36
add a comment |
My plan is to set up 3 cron jobs because these will be required to run at certain times. Here is how I have it setup currently: Daily - everyday at 2PM Weekly - every Sunday at 11:59PM SemiAnnually - every last day of the month at 11:59PM Sorry I'm really new to scripting and I really appreciate your insight. I figured since it will run on 3 different occasions, it will go through the if statements to determine what file needs to be generated. My concern are the days like March 31st which will be a Sunday and the last day of the month.
– Chris Tran
Feb 8 at 2:18
For the last days of the month I'm just doing something like: 55 23 31 1,3,5,7,8,10,12 *
– Chris Tran
Feb 8 at 13:05
Sorry I'm just a little confused. So I'm defining the exec_file_Report function before the cases and calling then calling the function in each of the cases but not getting a report at all now. I tried doing it this way but using my if conditions but I get an TNS error when manually running.
– Chris Tran
Feb 8 at 13:48
Hey I just want to say thank you! I used cases previously but just tried passing the "day" as an argument. I'm really new to all this and your post really helped guide me to the answer. I will post an update on how I achieved this with your insight when I get back home. Again, thank you!!
– Chris Tran
Feb 8 at 14:36
My plan is to set up 3 cron jobs because these will be required to run at certain times. Here is how I have it setup currently: Daily - everyday at 2PM Weekly - every Sunday at 11:59PM SemiAnnually - every last day of the month at 11:59PM Sorry I'm really new to scripting and I really appreciate your insight. I figured since it will run on 3 different occasions, it will go through the if statements to determine what file needs to be generated. My concern are the days like March 31st which will be a Sunday and the last day of the month.
– Chris Tran
Feb 8 at 2:18
My plan is to set up 3 cron jobs because these will be required to run at certain times. Here is how I have it setup currently: Daily - everyday at 2PM Weekly - every Sunday at 11:59PM SemiAnnually - every last day of the month at 11:59PM Sorry I'm really new to scripting and I really appreciate your insight. I figured since it will run on 3 different occasions, it will go through the if statements to determine what file needs to be generated. My concern are the days like March 31st which will be a Sunday and the last day of the month.
– Chris Tran
Feb 8 at 2:18
For the last days of the month I'm just doing something like: 55 23 31 1,3,5,7,8,10,12 *
– Chris Tran
Feb 8 at 13:05
For the last days of the month I'm just doing something like: 55 23 31 1,3,5,7,8,10,12 *
– Chris Tran
Feb 8 at 13:05
Sorry I'm just a little confused. So I'm defining the exec_file_Report function before the cases and calling then calling the function in each of the cases but not getting a report at all now. I tried doing it this way but using my if conditions but I get an TNS error when manually running.
– Chris Tran
Feb 8 at 13:48
Sorry I'm just a little confused. So I'm defining the exec_file_Report function before the cases and calling then calling the function in each of the cases but not getting a report at all now. I tried doing it this way but using my if conditions but I get an TNS error when manually running.
– Chris Tran
Feb 8 at 13:48
Hey I just want to say thank you! I used cases previously but just tried passing the "day" as an argument. I'm really new to all this and your post really helped guide me to the answer. I will post an update on how I achieved this with your insight when I get back home. Again, thank you!!
– Chris Tran
Feb 8 at 14:36
Hey I just want to say thank you! I used cases previously but just tried passing the "day" as an argument. I'm really new to all this and your post really helped guide me to the answer. I will post an update on how I achieved this with your insight when I get back home. Again, thank you!!
– Chris Tran
Feb 8 at 14:36
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f499385%2fhow-do-i-generate-multiple-reports-im-only-getting-the-daily-report-right-now%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you try to explain this a little more clearly? Like, what do you want to happen? Why are you testing
if [ $_day -ge 1 ] || [ $_day -le 7 ]
? Isn’t that always true? Are you just running this script 429 (365+52+12) times per year? Is this your “real” code, or just a dummy test version? … … … … … … … … … … … … … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete.– G-Man
Feb 8 at 1:29
This is currently a test version because I want them all to be true thus, generate all 3 reports. This is to see if days like March 31st which is the last day of month and a Sunday, will generate a report for both Weekly (Sunday) and semiannual (last day of month).
– Chris Tran
Feb 8 at 1:38