How to find the last day of the month's file in the previous month folder and how to should code in loop?












0















enter image description hereI have an S3 bucket...In which every month new folder will be created and every day new files will be added into the particular folder and i should mail them...Now the thing is that every month 1st day of the file will be saved in the previous month's folder...eg: Feb 1st file will be saved in jan's folder. New folder of the month will be created on the second day of the month..Folder will be created like 02_Feb,03_March...Below is my code..



aws s3 ls s3://project/js/Historical/$(date +%Y)/$(date +%m)_$(date +%B) | sort -rh | head -n 1 | awk {' print $2'}



Path of the folder will be like project/js/Historical/2019/)01_Jan



The above code is working fine...but it fails in the case of the last day of the month....Because On Feb 1st...There will be only one folder i.e.01_Jan ...only on 2nd feb new folder will be created...
My requirement is that on every first day of the month the file should be checked in the previous month folder



aws s3 ls s3://projrct/js/Historical/$(date +%Y)/$(date +%m)_$(date +%B/) | grep ${DATE} | sort -rh | head -n 5 | awk {' print $1"t"$2"t"$4'} | mail -s "s3" "abc@gmail.com"


This code works fine ..but the thing is that when the file is not received it sends the mail with empty body...Instead of that i should send the mail's body as "fail" ..How can i put this in loop










share|improve this question




















  • 2





    Welcome to the site. I am struggling to see what you are asking. Is having the 1st day as part of the previous month intentional? Are you trying to fix this? Are you trying to do something else? Please proof-read, and edit to make it clear.

    – ctrl-alt-delor
    14 hours ago






  • 1





    Your question isn't clear. If your problem is on the first of February, you create another file/directory starting with 01_ and can't properly sort 01_Feb and 01_Jan, then use a different naming scheme. Like 0101 for Jan 1, 0131 for Jan 31, and 0201 for Feb 1.

    – Andrew Henle
    14 hours ago











  • Hi sir...thank u for replying....On every month new folder will be created for eg..01_Jan (for january) 02_Feb (for February)...And every day new files will be added into the current month...The problem is that the file for the first day of the month is stored in the previous month folder for eg : March1st file will be stored in Feb month folder...And the new folder for the March will be created on the second day of the month that is on march 2nd....Acc to the above mentioned code the code fails on every 1st day of the month..Pls help me to solve the problem

    – disha
    14 hours ago











  • @Andrew The month's file is created by the company...On every 1st day of the month file will be generated and stored in the previous month folder...My requirement is like on every 1st the file should be checked in the previous month folder..Pls help me

    – disha
    14 hours ago











  • Who determines which folder the file will be put into? How is that determined? Is there a possibility that there's a timezone problem somewhere? You need to provide a lot more details.

    – Andrew Henle
    14 hours ago


















0















enter image description hereI have an S3 bucket...In which every month new folder will be created and every day new files will be added into the particular folder and i should mail them...Now the thing is that every month 1st day of the file will be saved in the previous month's folder...eg: Feb 1st file will be saved in jan's folder. New folder of the month will be created on the second day of the month..Folder will be created like 02_Feb,03_March...Below is my code..



aws s3 ls s3://project/js/Historical/$(date +%Y)/$(date +%m)_$(date +%B) | sort -rh | head -n 1 | awk {' print $2'}



Path of the folder will be like project/js/Historical/2019/)01_Jan



The above code is working fine...but it fails in the case of the last day of the month....Because On Feb 1st...There will be only one folder i.e.01_Jan ...only on 2nd feb new folder will be created...
My requirement is that on every first day of the month the file should be checked in the previous month folder



aws s3 ls s3://projrct/js/Historical/$(date +%Y)/$(date +%m)_$(date +%B/) | grep ${DATE} | sort -rh | head -n 5 | awk {' print $1"t"$2"t"$4'} | mail -s "s3" "abc@gmail.com"


This code works fine ..but the thing is that when the file is not received it sends the mail with empty body...Instead of that i should send the mail's body as "fail" ..How can i put this in loop










share|improve this question




















  • 2





    Welcome to the site. I am struggling to see what you are asking. Is having the 1st day as part of the previous month intentional? Are you trying to fix this? Are you trying to do something else? Please proof-read, and edit to make it clear.

    – ctrl-alt-delor
    14 hours ago






  • 1





    Your question isn't clear. If your problem is on the first of February, you create another file/directory starting with 01_ and can't properly sort 01_Feb and 01_Jan, then use a different naming scheme. Like 0101 for Jan 1, 0131 for Jan 31, and 0201 for Feb 1.

    – Andrew Henle
    14 hours ago











  • Hi sir...thank u for replying....On every month new folder will be created for eg..01_Jan (for january) 02_Feb (for February)...And every day new files will be added into the current month...The problem is that the file for the first day of the month is stored in the previous month folder for eg : March1st file will be stored in Feb month folder...And the new folder for the March will be created on the second day of the month that is on march 2nd....Acc to the above mentioned code the code fails on every 1st day of the month..Pls help me to solve the problem

    – disha
    14 hours ago











  • @Andrew The month's file is created by the company...On every 1st day of the month file will be generated and stored in the previous month folder...My requirement is like on every 1st the file should be checked in the previous month folder..Pls help me

    – disha
    14 hours ago











  • Who determines which folder the file will be put into? How is that determined? Is there a possibility that there's a timezone problem somewhere? You need to provide a lot more details.

    – Andrew Henle
    14 hours ago
















0












0








0








enter image description hereI have an S3 bucket...In which every month new folder will be created and every day new files will be added into the particular folder and i should mail them...Now the thing is that every month 1st day of the file will be saved in the previous month's folder...eg: Feb 1st file will be saved in jan's folder. New folder of the month will be created on the second day of the month..Folder will be created like 02_Feb,03_March...Below is my code..



aws s3 ls s3://project/js/Historical/$(date +%Y)/$(date +%m)_$(date +%B) | sort -rh | head -n 1 | awk {' print $2'}



Path of the folder will be like project/js/Historical/2019/)01_Jan



The above code is working fine...but it fails in the case of the last day of the month....Because On Feb 1st...There will be only one folder i.e.01_Jan ...only on 2nd feb new folder will be created...
My requirement is that on every first day of the month the file should be checked in the previous month folder



aws s3 ls s3://projrct/js/Historical/$(date +%Y)/$(date +%m)_$(date +%B/) | grep ${DATE} | sort -rh | head -n 5 | awk {' print $1"t"$2"t"$4'} | mail -s "s3" "abc@gmail.com"


This code works fine ..but the thing is that when the file is not received it sends the mail with empty body...Instead of that i should send the mail's body as "fail" ..How can i put this in loop










share|improve this question
















enter image description hereI have an S3 bucket...In which every month new folder will be created and every day new files will be added into the particular folder and i should mail them...Now the thing is that every month 1st day of the file will be saved in the previous month's folder...eg: Feb 1st file will be saved in jan's folder. New folder of the month will be created on the second day of the month..Folder will be created like 02_Feb,03_March...Below is my code..



aws s3 ls s3://project/js/Historical/$(date +%Y)/$(date +%m)_$(date +%B) | sort -rh | head -n 1 | awk {' print $2'}



Path of the folder will be like project/js/Historical/2019/)01_Jan



The above code is working fine...but it fails in the case of the last day of the month....Because On Feb 1st...There will be only one folder i.e.01_Jan ...only on 2nd feb new folder will be created...
My requirement is that on every first day of the month the file should be checked in the previous month folder



aws s3 ls s3://projrct/js/Historical/$(date +%Y)/$(date +%m)_$(date +%B/) | grep ${DATE} | sort -rh | head -n 5 | awk {' print $1"t"$2"t"$4'} | mail -s "s3" "abc@gmail.com"


This code works fine ..but the thing is that when the file is not received it sends the mail with empty body...Instead of that i should send the mail's body as "fail" ..How can i put this in loop







linux date amazon-s3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 15 mins ago







disha

















asked 14 hours ago









dishadisha

13




13








  • 2





    Welcome to the site. I am struggling to see what you are asking. Is having the 1st day as part of the previous month intentional? Are you trying to fix this? Are you trying to do something else? Please proof-read, and edit to make it clear.

    – ctrl-alt-delor
    14 hours ago






  • 1





    Your question isn't clear. If your problem is on the first of February, you create another file/directory starting with 01_ and can't properly sort 01_Feb and 01_Jan, then use a different naming scheme. Like 0101 for Jan 1, 0131 for Jan 31, and 0201 for Feb 1.

    – Andrew Henle
    14 hours ago











  • Hi sir...thank u for replying....On every month new folder will be created for eg..01_Jan (for january) 02_Feb (for February)...And every day new files will be added into the current month...The problem is that the file for the first day of the month is stored in the previous month folder for eg : March1st file will be stored in Feb month folder...And the new folder for the March will be created on the second day of the month that is on march 2nd....Acc to the above mentioned code the code fails on every 1st day of the month..Pls help me to solve the problem

    – disha
    14 hours ago











  • @Andrew The month's file is created by the company...On every 1st day of the month file will be generated and stored in the previous month folder...My requirement is like on every 1st the file should be checked in the previous month folder..Pls help me

    – disha
    14 hours ago











  • Who determines which folder the file will be put into? How is that determined? Is there a possibility that there's a timezone problem somewhere? You need to provide a lot more details.

    – Andrew Henle
    14 hours ago
















  • 2





    Welcome to the site. I am struggling to see what you are asking. Is having the 1st day as part of the previous month intentional? Are you trying to fix this? Are you trying to do something else? Please proof-read, and edit to make it clear.

    – ctrl-alt-delor
    14 hours ago






  • 1





    Your question isn't clear. If your problem is on the first of February, you create another file/directory starting with 01_ and can't properly sort 01_Feb and 01_Jan, then use a different naming scheme. Like 0101 for Jan 1, 0131 for Jan 31, and 0201 for Feb 1.

    – Andrew Henle
    14 hours ago











  • Hi sir...thank u for replying....On every month new folder will be created for eg..01_Jan (for january) 02_Feb (for February)...And every day new files will be added into the current month...The problem is that the file for the first day of the month is stored in the previous month folder for eg : March1st file will be stored in Feb month folder...And the new folder for the March will be created on the second day of the month that is on march 2nd....Acc to the above mentioned code the code fails on every 1st day of the month..Pls help me to solve the problem

    – disha
    14 hours ago











  • @Andrew The month's file is created by the company...On every 1st day of the month file will be generated and stored in the previous month folder...My requirement is like on every 1st the file should be checked in the previous month folder..Pls help me

    – disha
    14 hours ago











  • Who determines which folder the file will be put into? How is that determined? Is there a possibility that there's a timezone problem somewhere? You need to provide a lot more details.

    – Andrew Henle
    14 hours ago










2




2





Welcome to the site. I am struggling to see what you are asking. Is having the 1st day as part of the previous month intentional? Are you trying to fix this? Are you trying to do something else? Please proof-read, and edit to make it clear.

– ctrl-alt-delor
14 hours ago





Welcome to the site. I am struggling to see what you are asking. Is having the 1st day as part of the previous month intentional? Are you trying to fix this? Are you trying to do something else? Please proof-read, and edit to make it clear.

– ctrl-alt-delor
14 hours ago




1




1





Your question isn't clear. If your problem is on the first of February, you create another file/directory starting with 01_ and can't properly sort 01_Feb and 01_Jan, then use a different naming scheme. Like 0101 for Jan 1, 0131 for Jan 31, and 0201 for Feb 1.

– Andrew Henle
14 hours ago





Your question isn't clear. If your problem is on the first of February, you create another file/directory starting with 01_ and can't properly sort 01_Feb and 01_Jan, then use a different naming scheme. Like 0101 for Jan 1, 0131 for Jan 31, and 0201 for Feb 1.

– Andrew Henle
14 hours ago













Hi sir...thank u for replying....On every month new folder will be created for eg..01_Jan (for january) 02_Feb (for February)...And every day new files will be added into the current month...The problem is that the file for the first day of the month is stored in the previous month folder for eg : March1st file will be stored in Feb month folder...And the new folder for the March will be created on the second day of the month that is on march 2nd....Acc to the above mentioned code the code fails on every 1st day of the month..Pls help me to solve the problem

– disha
14 hours ago





Hi sir...thank u for replying....On every month new folder will be created for eg..01_Jan (for january) 02_Feb (for February)...And every day new files will be added into the current month...The problem is that the file for the first day of the month is stored in the previous month folder for eg : March1st file will be stored in Feb month folder...And the new folder for the March will be created on the second day of the month that is on march 2nd....Acc to the above mentioned code the code fails on every 1st day of the month..Pls help me to solve the problem

– disha
14 hours ago













@Andrew The month's file is created by the company...On every 1st day of the month file will be generated and stored in the previous month folder...My requirement is like on every 1st the file should be checked in the previous month folder..Pls help me

– disha
14 hours ago





@Andrew The month's file is created by the company...On every 1st day of the month file will be generated and stored in the previous month folder...My requirement is like on every 1st the file should be checked in the previous month folder..Pls help me

– disha
14 hours ago













Who determines which folder the file will be put into? How is that determined? Is there a possibility that there's a timezone problem somewhere? You need to provide a lot more details.

– Andrew Henle
14 hours ago







Who determines which folder the file will be put into? How is that determined? Is there a possibility that there's a timezone problem somewhere? You need to provide a lot more details.

– Andrew Henle
14 hours ago












0






active

oldest

votes











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f501189%2fhow-to-find-the-last-day-of-the-months-file-in-the-previous-month-folder-and-ho%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f501189%2fhow-to-find-the-last-day-of-the-months-file-in-the-previous-month-folder-and-ho%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

濃尾地震

How to rewrite equation of hyperbola in standard form

No ethernet ip address in my vocore2