I need to check a list of directories if it contains a directory newer than 1 month before nowlist all files...
An 'if constexpr branch' does not get discarded inside lambda that is inside a template function
How to reply this mail from potential PhD professor?
How to implement float hashing with approximate equality
If 1. e4 c6 is considered as a sound defense for black, why is 1. c3 so rare?
What is the most remote airport from the center of the city it supposedly serves?
Map one pandas column using two dictionaries
Hang 20lb projector screen on Hardieplank
Is Cola "probably the best-known" Latin word in the world? If not, which might it be?
Transfer over $10k
Is this homebrew race based on the Draco Volans lizard species balanced?
Entropy as a function of temperature: is temperature well defined?
Selecting a secure PIN for building access
Would "lab meat" be able to feed a much larger global population
Conflicting terms and the definition of a «child»
Unidentified items in bicycle tube repair kit
Does the Darkness spell dispel the Color Spray and Flaming Sphere spells?
CRT Oscilloscope - part of the plot is missing
Airbnb - host wants to reduce rooms, can we get refund?
Why do money exchangers give different rates to different bills
Accidentally deleted the "/usr/share" folder
LT Spice Voltage Output
What was the state of the German rail system in 1944?
Is it the same airport YUL and YMQ in Canada?
Who died in the Game of Thrones episode, "The Long Night"?
I need to check a list of directories if it contains a directory newer than 1 month before now
list all files newer than given timestamp and sort themExpression error in bash scriptcannot move Directory not emptyPreform operation in bash only if a variable is less than a second variablemysql backup and rsync script problemcleaning output of a script so it's descending, gives package names and cleanly existsFind list of directories one level deep from matching directoryList directory hierarchy with files before subdirectoriesHouskeep old files and dirsEqually divide contents of a directory between disks - rounded up to the nearest top level directory
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I'll try to explain what i have done until now.
First of all i have build the list of directories i want to investigate with the code below:
$MDIR="/home/user/scripts/fcron"
DIRS=`ls -l $MDIR | egrep '^d' | awk '{print $9}' | grep ^$ts-`
The DIRS list now contain directory names of the form :
NETGEAR-2013-06-30
NETGEAR-2013-07-01
........
NETGEAR-2013-05-05
Now i need to check all those directories (contained in list DIRS) and i need to find one that is newer than 1 month before now (e.g 27 or 29 days). In case i find one match i need to exit the script.
In 'pseudocode' i would write:
for dir is DIRS:
if dir is newer than 30 days old:
exit the script
else:
continue
My difficulty is in translating just the above 'pseudocode' in a bash script.
/////Latest Update/////
OK i have updated the part with the pseudocode with this:
for DIR is $DIRS;
do
if (( $(stat -c %Y "$dir") < $(date +%s) - 3600*24*30 )); then
echo "exiting!!"
exit
else
continue
fi
done
But now i am getting this :
line 40: syntax error: unexpected word (expecting "do")
bash shell-script
add a comment |
I'll try to explain what i have done until now.
First of all i have build the list of directories i want to investigate with the code below:
$MDIR="/home/user/scripts/fcron"
DIRS=`ls -l $MDIR | egrep '^d' | awk '{print $9}' | grep ^$ts-`
The DIRS list now contain directory names of the form :
NETGEAR-2013-06-30
NETGEAR-2013-07-01
........
NETGEAR-2013-05-05
Now i need to check all those directories (contained in list DIRS) and i need to find one that is newer than 1 month before now (e.g 27 or 29 days). In case i find one match i need to exit the script.
In 'pseudocode' i would write:
for dir is DIRS:
if dir is newer than 30 days old:
exit the script
else:
continue
My difficulty is in translating just the above 'pseudocode' in a bash script.
/////Latest Update/////
OK i have updated the part with the pseudocode with this:
for DIR is $DIRS;
do
if (( $(stat -c %Y "$dir") < $(date +%s) - 3600*24*30 )); then
echo "exiting!!"
exit
else
continue
fi
done
But now i am getting this :
line 40: syntax error: unexpected word (expecting "do")
bash shell-script
add a comment |
I'll try to explain what i have done until now.
First of all i have build the list of directories i want to investigate with the code below:
$MDIR="/home/user/scripts/fcron"
DIRS=`ls -l $MDIR | egrep '^d' | awk '{print $9}' | grep ^$ts-`
The DIRS list now contain directory names of the form :
NETGEAR-2013-06-30
NETGEAR-2013-07-01
........
NETGEAR-2013-05-05
Now i need to check all those directories (contained in list DIRS) and i need to find one that is newer than 1 month before now (e.g 27 or 29 days). In case i find one match i need to exit the script.
In 'pseudocode' i would write:
for dir is DIRS:
if dir is newer than 30 days old:
exit the script
else:
continue
My difficulty is in translating just the above 'pseudocode' in a bash script.
/////Latest Update/////
OK i have updated the part with the pseudocode with this:
for DIR is $DIRS;
do
if (( $(stat -c %Y "$dir") < $(date +%s) - 3600*24*30 )); then
echo "exiting!!"
exit
else
continue
fi
done
But now i am getting this :
line 40: syntax error: unexpected word (expecting "do")
bash shell-script
I'll try to explain what i have done until now.
First of all i have build the list of directories i want to investigate with the code below:
$MDIR="/home/user/scripts/fcron"
DIRS=`ls -l $MDIR | egrep '^d' | awk '{print $9}' | grep ^$ts-`
The DIRS list now contain directory names of the form :
NETGEAR-2013-06-30
NETGEAR-2013-07-01
........
NETGEAR-2013-05-05
Now i need to check all those directories (contained in list DIRS) and i need to find one that is newer than 1 month before now (e.g 27 or 29 days). In case i find one match i need to exit the script.
In 'pseudocode' i would write:
for dir is DIRS:
if dir is newer than 30 days old:
exit the script
else:
continue
My difficulty is in translating just the above 'pseudocode' in a bash script.
/////Latest Update/////
OK i have updated the part with the pseudocode with this:
for DIR is $DIRS;
do
if (( $(stat -c %Y "$dir") < $(date +%s) - 3600*24*30 )); then
echo "exiting!!"
exit
else
continue
fi
done
But now i am getting this :
line 40: syntax error: unexpected word (expecting "do")
bash shell-script
bash shell-script
edited 56 mins ago
Rui F Ribeiro
42.5k1485146
42.5k1485146
asked Jun 30 '13 at 22:46
Vaios ArgiropoulosVaios Argiropoulos
63211
63211
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Try doing this :
dirs='dir1 dir2 dir3'
for dir is $dirs; do
if (( $(stat -c %Y "$dir") < $(date +%s) - 3600*24*30 )); then
exit
else
continue
fi
done
I'll try later. I'am off to bed.
– Vaios Argiropoulos
Jun 30 '13 at 22:59
add a comment |
The general approach:
find . -mindepth 1 -maxdepth 1 -type d
-newermt "$(date --date="1 month ago 00:00" --rfc-3339=seconds)"
Using your DIRS:
find $DIRS -maxdepth 0 -type d
-newermt "$(date --date="1 month ago 00:00" --rfc-3339=seconds)"
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%2f81265%2fi-need-to-check-a-list-of-directories-if-it-contains-a-directory-newer-than-1-mo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try doing this :
dirs='dir1 dir2 dir3'
for dir is $dirs; do
if (( $(stat -c %Y "$dir") < $(date +%s) - 3600*24*30 )); then
exit
else
continue
fi
done
I'll try later. I'am off to bed.
– Vaios Argiropoulos
Jun 30 '13 at 22:59
add a comment |
Try doing this :
dirs='dir1 dir2 dir3'
for dir is $dirs; do
if (( $(stat -c %Y "$dir") < $(date +%s) - 3600*24*30 )); then
exit
else
continue
fi
done
I'll try later. I'am off to bed.
– Vaios Argiropoulos
Jun 30 '13 at 22:59
add a comment |
Try doing this :
dirs='dir1 dir2 dir3'
for dir is $dirs; do
if (( $(stat -c %Y "$dir") < $(date +%s) - 3600*24*30 )); then
exit
else
continue
fi
done
Try doing this :
dirs='dir1 dir2 dir3'
for dir is $dirs; do
if (( $(stat -c %Y "$dir") < $(date +%s) - 3600*24*30 )); then
exit
else
continue
fi
done
answered Jun 30 '13 at 22:51
Gilles QuenotGilles Quenot
16.6k14054
16.6k14054
I'll try later. I'am off to bed.
– Vaios Argiropoulos
Jun 30 '13 at 22:59
add a comment |
I'll try later. I'am off to bed.
– Vaios Argiropoulos
Jun 30 '13 at 22:59
I'll try later. I'am off to bed.
– Vaios Argiropoulos
Jun 30 '13 at 22:59
I'll try later. I'am off to bed.
– Vaios Argiropoulos
Jun 30 '13 at 22:59
add a comment |
The general approach:
find . -mindepth 1 -maxdepth 1 -type d
-newermt "$(date --date="1 month ago 00:00" --rfc-3339=seconds)"
Using your DIRS:
find $DIRS -maxdepth 0 -type d
-newermt "$(date --date="1 month ago 00:00" --rfc-3339=seconds)"
add a comment |
The general approach:
find . -mindepth 1 -maxdepth 1 -type d
-newermt "$(date --date="1 month ago 00:00" --rfc-3339=seconds)"
Using your DIRS:
find $DIRS -maxdepth 0 -type d
-newermt "$(date --date="1 month ago 00:00" --rfc-3339=seconds)"
add a comment |
The general approach:
find . -mindepth 1 -maxdepth 1 -type d
-newermt "$(date --date="1 month ago 00:00" --rfc-3339=seconds)"
Using your DIRS:
find $DIRS -maxdepth 0 -type d
-newermt "$(date --date="1 month ago 00:00" --rfc-3339=seconds)"
The general approach:
find . -mindepth 1 -maxdepth 1 -type d
-newermt "$(date --date="1 month ago 00:00" --rfc-3339=seconds)"
Using your DIRS:
find $DIRS -maxdepth 0 -type d
-newermt "$(date --date="1 month ago 00:00" --rfc-3339=seconds)"
answered Jun 30 '13 at 23:06
Hauke LagingHauke Laging
58.2k1289137
58.2k1289137
add a comment |
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%2f81265%2fi-need-to-check-a-list-of-directories-if-it-contains-a-directory-newer-than-1-mo%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