delete multiple users
I am the root user and I am setting up a menu for another user to use. This other user will only get this menu.
There are two options that are interlinked: the first option is to search users. The code I got is:
last | awk '{print $1,$4,$5,$6,$7} '
I have checked this code and it works, it shows me the usernames and the day they last logged on.
For the second option: I want to be able to set a date, and them delete users who haven't been active since that date, using the output of the above command.
I am using Linux Mint and Vim text editor.
awk last
bumped to the homepage by Community♦ 23 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I am the root user and I am setting up a menu for another user to use. This other user will only get this menu.
There are two options that are interlinked: the first option is to search users. The code I got is:
last | awk '{print $1,$4,$5,$6,$7} '
I have checked this code and it works, it shows me the usernames and the day they last logged on.
For the second option: I want to be able to set a date, and them delete users who haven't been active since that date, using the output of the above command.
I am using Linux Mint and Vim text editor.
awk last
bumped to the homepage by Community♦ 23 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
A question—i.e. a sentence with a question mark (?)—would greatly help to indicate what you try to ask.
– Anthon
Dec 5 '14 at 13:41
i want to know a way to delete multiple users who haven't logged in for a long period of time
– user2995836
Dec 5 '14 at 13:56
correction i want to enter a date then delete users who have been inactive since that date
– user2995836
Dec 5 '14 at 14:03
add a comment |
I am the root user and I am setting up a menu for another user to use. This other user will only get this menu.
There are two options that are interlinked: the first option is to search users. The code I got is:
last | awk '{print $1,$4,$5,$6,$7} '
I have checked this code and it works, it shows me the usernames and the day they last logged on.
For the second option: I want to be able to set a date, and them delete users who haven't been active since that date, using the output of the above command.
I am using Linux Mint and Vim text editor.
awk last
I am the root user and I am setting up a menu for another user to use. This other user will only get this menu.
There are two options that are interlinked: the first option is to search users. The code I got is:
last | awk '{print $1,$4,$5,$6,$7} '
I have checked this code and it works, it shows me the usernames and the day they last logged on.
For the second option: I want to be able to set a date, and them delete users who haven't been active since that date, using the output of the above command.
I am using Linux Mint and Vim text editor.
awk last
awk last
edited Dec 5 '14 at 13:42
Alaa Ali
9602920
9602920
asked Dec 5 '14 at 12:26
user2995836user2995836
484
484
bumped to the homepage by Community♦ 23 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 23 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
A question—i.e. a sentence with a question mark (?)—would greatly help to indicate what you try to ask.
– Anthon
Dec 5 '14 at 13:41
i want to know a way to delete multiple users who haven't logged in for a long period of time
– user2995836
Dec 5 '14 at 13:56
correction i want to enter a date then delete users who have been inactive since that date
– user2995836
Dec 5 '14 at 14:03
add a comment |
A question—i.e. a sentence with a question mark (?)—would greatly help to indicate what you try to ask.
– Anthon
Dec 5 '14 at 13:41
i want to know a way to delete multiple users who haven't logged in for a long period of time
– user2995836
Dec 5 '14 at 13:56
correction i want to enter a date then delete users who have been inactive since that date
– user2995836
Dec 5 '14 at 14:03
A question—i.e. a sentence with a question mark (
?)—would greatly help to indicate what you try to ask.– Anthon
Dec 5 '14 at 13:41
A question—i.e. a sentence with a question mark (
?)—would greatly help to indicate what you try to ask.– Anthon
Dec 5 '14 at 13:41
i want to know a way to delete multiple users who haven't logged in for a long period of time
– user2995836
Dec 5 '14 at 13:56
i want to know a way to delete multiple users who haven't logged in for a long period of time
– user2995836
Dec 5 '14 at 13:56
correction i want to enter a date then delete users who have been inactive since that date
– user2995836
Dec 5 '14 at 14:03
correction i want to enter a date then delete users who have been inactive since that date
– user2995836
Dec 5 '14 at 14:03
add a comment |
2 Answers
2
active
oldest
votes
You can do it like so:
root@host# lastlog -b Num_Days_Since_Last_Login | egrep -v "^Username|Never logged in" | awk '{print $1}' | xargs -i userdel {}
Where Num_Days_Since_Last_Login is an integer number of days since last login...
add a comment |
A complete solution :
#!/bin/bash
maxdate=$(date -d "$1" +%s) || exit 1
daysdate=$((($(date +%s)-maxdate)/(3600*24)))
LANG=C lastlog -b $daysdate -u 1000- |
awk 'NR>1{print $1}' |
xargs -n1 echo userdel
Test it and remove echo to do it forReal™.
Example usage :
./script.sh 'Fri Dec 5 17:00:06 CET 2013'
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%2f171651%2fdelete-multiple-users%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
You can do it like so:
root@host# lastlog -b Num_Days_Since_Last_Login | egrep -v "^Username|Never logged in" | awk '{print $1}' | xargs -i userdel {}
Where Num_Days_Since_Last_Login is an integer number of days since last login...
add a comment |
You can do it like so:
root@host# lastlog -b Num_Days_Since_Last_Login | egrep -v "^Username|Never logged in" | awk '{print $1}' | xargs -i userdel {}
Where Num_Days_Since_Last_Login is an integer number of days since last login...
add a comment |
You can do it like so:
root@host# lastlog -b Num_Days_Since_Last_Login | egrep -v "^Username|Never logged in" | awk '{print $1}' | xargs -i userdel {}
Where Num_Days_Since_Last_Login is an integer number of days since last login...
You can do it like so:
root@host# lastlog -b Num_Days_Since_Last_Login | egrep -v "^Username|Never logged in" | awk '{print $1}' | xargs -i userdel {}
Where Num_Days_Since_Last_Login is an integer number of days since last login...
answered Dec 5 '14 at 15:15
KirillKirill
323
323
add a comment |
add a comment |
A complete solution :
#!/bin/bash
maxdate=$(date -d "$1" +%s) || exit 1
daysdate=$((($(date +%s)-maxdate)/(3600*24)))
LANG=C lastlog -b $daysdate -u 1000- |
awk 'NR>1{print $1}' |
xargs -n1 echo userdel
Test it and remove echo to do it forReal™.
Example usage :
./script.sh 'Fri Dec 5 17:00:06 CET 2013'
add a comment |
A complete solution :
#!/bin/bash
maxdate=$(date -d "$1" +%s) || exit 1
daysdate=$((($(date +%s)-maxdate)/(3600*24)))
LANG=C lastlog -b $daysdate -u 1000- |
awk 'NR>1{print $1}' |
xargs -n1 echo userdel
Test it and remove echo to do it forReal™.
Example usage :
./script.sh 'Fri Dec 5 17:00:06 CET 2013'
add a comment |
A complete solution :
#!/bin/bash
maxdate=$(date -d "$1" +%s) || exit 1
daysdate=$((($(date +%s)-maxdate)/(3600*24)))
LANG=C lastlog -b $daysdate -u 1000- |
awk 'NR>1{print $1}' |
xargs -n1 echo userdel
Test it and remove echo to do it forReal™.
Example usage :
./script.sh 'Fri Dec 5 17:00:06 CET 2013'
A complete solution :
#!/bin/bash
maxdate=$(date -d "$1" +%s) || exit 1
daysdate=$((($(date +%s)-maxdate)/(3600*24)))
LANG=C lastlog -b $daysdate -u 1000- |
awk 'NR>1{print $1}' |
xargs -n1 echo userdel
Test it and remove echo to do it forReal™.
Example usage :
./script.sh 'Fri Dec 5 17:00:06 CET 2013'
edited Dec 5 '14 at 16:40
answered Dec 5 '14 at 16:21
Gilles QuenotGilles Quenot
16k13951
16k13951
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%2f171651%2fdelete-multiple-users%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
A question—i.e. a sentence with a question mark (
?)—would greatly help to indicate what you try to ask.– Anthon
Dec 5 '14 at 13:41
i want to know a way to delete multiple users who haven't logged in for a long period of time
– user2995836
Dec 5 '14 at 13:56
correction i want to enter a date then delete users who have been inactive since that date
– user2995836
Dec 5 '14 at 14:03