Set expire date for users


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Set expire date for users
# 1  
Old 09-11-2014
Set expire date for users

hello
chage command is a useful command for set expire date (suspend user) :

-E switch will update the “Account expires” value as shown below:
chage -E "2009-05-31" username

how can i write this shell script which can find present date and plus it with the value that user set,
like today is 2014-05-31, user enter 60 when script ask hi the expire period,
script must add 60 days to 2014-05-31 and store it in date.txt file
# 2  
Old 09-11-2014
Hello Nimafire,

You can try with following command.

While user creation you can use following command.
Code:
useradd -e `date -d "60 days" +"%Y-%m-%d"` someuser

To change user's expiration date who already exist.
Code:
chage -E `date -d "60 days" +"%Y-%m-%d"` someuser


Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 09-11-2014
very god,
ok now how can i list all users from /home and add them to $USERNAMES with loop ?
this script has to list all users from /home with ls /home
chage -l $USERNAMES | grep "Account expires" | cut -d: -f2 2> LIST.txt

---------- Post updated at 11:05 AM ---------- Previous update was at 10:21 AM ----------

checkout this code, the output is not what i want,
echo username + expire date to new dile

Code:
echo "`ls /home/`"$'\r' > /root/Desktop/userslist
for i in `cat /root/Desktop/userslist`
do
explist=`chage -l $i | grep "Account expires" | cut -d: -f2`
echo "$i IS EXPIRE IN $explist" > /root/Desktop/LIST
done

---------- Post updated at 12:49 PM ---------- Previous update was at 11:05 AM ----------

chage
send an unknown user error after 3 times, checout these errors
chage: unknown user user4
chage: unknown user nima5

you can run my script in your machine and check it will stop after for or while command run 3 times,
# 4  
Old 09-11-2014
Try this corrected version, which is based on your own attempts:
Code:
ls /home > /root/Desktop/userslist

#empty LIST file
>/root/Desktop/LIST

for i in `cat /root/Desktop/userslist`
 do
 explist=`chage -l $i | grep "Account expires" | cut -d: -f2`
 echo "$i IS EXPIRE IN $explist" >> /root/Desktop/LIST
done

If it works, please use the while loop version, which is more appropriate for this task. It does the same as the for loop, but in a "cleaner" way:
Code:
ls /home > /root/Desktop/userslist

#empty LIST file
>/root/Desktop/LIST

while read user
 do
 explist=`chage -l $user | grep "Account expires" | cut -d: -f2`
 echo "$user IS EXPIRE IN $explist" >> /root/Desktop/LIST
done < /root/Desktop/userslist

This User Gave Thanks to junior-helper For This Post:
# 5  
Old 10-03-2014
is it possible to find first time that user login to system ?
checkout this:
user has been create in 10 september but first login is 20 september
# 6  
Old 10-03-2014
Try the last command... if available on your system.
# 7  
Old 10-03-2014
Quote:
Originally Posted by RudiC
Try the last command... if available on your system.
how can i uss this to find first login time of "user2" for example ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date: invalid date trying to set Linux date in specific format

i try to set linux date & time in specific format but it keep giving me error Example : date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" or date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" keep giving me this error : date: invalid date ‘19-01-2017 00:05:01' Please use CODE tags... (7 Replies)
Discussion started by: umen
7 Replies

2. HP-UX

How to set variable for users with no home directory?

Hi I need to set $HISTFILE for a user with no home directory. How to go about it because this user does not have a .profilefile. (5 Replies)
Discussion started by: fretagi
5 Replies

3. SCO

Cannot use 'date -t' to set the system date and time

Hi! All, I am trying to reset the date and time since the change in time over the weekend. I cannot issue the command date -t 201703131330. The system gives me an error invalid option. This happens on my SCO OpenServer 5.0.7 and 5.0.6. Do anyone have an idea why? I even tried using... (6 Replies)
Discussion started by: trolley
6 Replies

4. Shell Programming and Scripting

Shell script to set user password to never expire in UNIX servers

Hi, I have a requirement where in i need to write a shell script to set users password to never expire. I know the command which is used to perform the same .. which is chage command. But, could not figure out how to do the same in shell script. Could you please help me with the shell... (3 Replies)
Discussion started by: suren424
3 Replies

5. UNIX for Dummies Questions & Answers

Set sudo access to expire on given day\date?

Scenario: Admin wants to grant user temporary access to sudo that will expire on an arbitrary date\day. Say, after 10 days, sudo rights disappear automatically. I'm sure there's a way to hack something together with a script or cron job, but I was wondering if anyone has a package \ tool \ other... (3 Replies)
Discussion started by: DustinT
3 Replies

6. UNIX for Dummies Questions & Answers

To set different file permissions for different users of same group

Hi, If User1, User2 and User3 are in the same group. User1 should not be able to view the files of User2 and User3. But User2 and User3 should be able to view all files. How to set permission for this. Please help. Thanks, Priya. (1 Reply)
Discussion started by: banupriyat
1 Replies

7. Shell Programming and Scripting

Set system date to some date (Sunos)

I am testing a script and need to change the system date to Nov 30 2009. I cannot seem to find a way to do this other than TZ command but it does not seem to work correctly. I tried TZ=GMT+168 date but it is returning todays date Mon Dec 7 19:48:11 GMT 2009 ...instead of Nov 30 2009 I... (4 Replies)
Discussion started by: hanton
4 Replies

8. Red Hat

set password not to expire

Hi All, Is this true on chage command? -M, MAX_DAYS Passing the number -1 as MAX_DAYS will remove checking a password's validity. Does this means password will not expire anymore? Thanks for any comment you may add. (0 Replies)
Discussion started by: itik
0 Replies

9. Solaris

EUID set for all non-root users

We have a Solaris box. I noticed that whenever any non-root user logins into the box and issues the command id the output is (for example) uid=42568(sam) gid=1245(sam) euid=0(root) egid=2(bin). I have not given any privileges to anyone explicitly. When I issued ls -l in the /usr/bin directory I... (1 Reply)
Discussion started by: chrisanto_2000
1 Replies

10. Solaris

Set Password Never Expire

Hello I want to set the password for user never expire through the command line. For your information the box is running under Solaris 8 platform. (2 Replies)
Discussion started by: shamsul
2 Replies
Login or Register to Ask a Question