LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-21-2003, 12:05 AM   #1
hanhan
LQ Newbie
 
Registered: Apr 2003
Location: melb
Posts: 3

Rep: Reputation: 0
shell script


Hi;
im a newbee for linux. i have a home work which i wrote as bellow. anybody can help me to correct what is wrong. im appreciated.

the question is:
write a script to check users' id and ensure they have:
1. specific min days to change password (7)
2. specific max days to change password (30)
3. specific warning days (5)
4. ensure the "last changed" setting for each user occured in the past and report any that do not match this (include the date set in the shadow file in the report)
if -o option is passed as a command line, interactively prompt the user do:
1. disabling accounts
2. force change a users password
3. force a user to change password at next login.
#!/bin/sh

if [ $# -ne 1 ]; then

cat /etc/passwd | while read line
do
if [ echo `awk -F: '{print $3}' $line` > 500 ]; then

username = echo `awk -F: '{print $1}' $line`
temp = echo `passwd -S $username`

if [ echo `awk -F: '{print $3}' temp` ne 7 ]; then
passwd -n7 $username
fi

if [ echo `awk -F: '{print $4}' temp` ne 30 ]; then
passwd -x30 $username
fi

if [ echo `awk -F: '{print $5}' temp` ne 5 ]; then
passwd -w5 $username
fi

if [ grep -v '\/[0-9][0-9]\/[0-9][0-9]\/2003' `echo `awk $2 temp`` ]; then
echo $line
fi
fi
done

else

cat /etc/passwd | while read line
do
if [ echo `awk -F: '{print $3}' $line` >= 500 ]; then

username = echo `awk -F: '{print $1}' $line`
temp = `passwd -S $username`

if [ echo `awk -F: '{print $3}' temp` ne 7 ]; then
passwd -n7 $username
fi

if [ echo `awk -F: '{print $4}' temp` ne 30 ]; then
passwd -x30 $username
fi

if [ echo `awk -F: '{print $5}' temp` ne 5 ]; then
passwd -w5 $username
fi

if [ grep -v '^\/[0-9][0-9]\/[0-9][0-9]\/2003' `echo `awk $2 temp`` ]; then
echo $line
fi

if [ $1 = -o ]; then
echo 'Enter the command as bellow:'
echo 'l -- for disable the password'
echo 'p -- force change a users password'
echo 'f -- force change his/her passwd at next login'

if [ $1 = l ]; then
passwd -l $username
fi

if [ $1 = p ]; then
passwd -x1 -n1 $username
fi

if [ $1 = f ]
passwd -f $username
fi

fi
fi
done

fi

exit 0
 
Old 04-21-2003, 01:39 AM   #2
hanhan
LQ Newbie
 
Registered: Apr 2003
Location: melb
Posts: 3

Original Poster
Rep: Reputation: 0
Re: shell script

[QUOTE]Originally posted by hanhan
[B]Hi;
im a newbee for linux. i have a home work which i wrote as bellow. anybody can help me to correct what is wrong. im appreciated.

the question is:
write a script to check users' id and ensure they have:
1. specific min days to change password (7)
2. specific max days to change password (30)
3. specific warning days (5)
4. ensure the "last changed" setting for each user occured in the past and report any that do not match this (include the date set in the shadow file in the report)
if -o option is passed as a command line, interactively prompt the user do:
1. disabling accounts
2. force change a users password
3. force a user to change password at next login.
#!/bin/sh

if [ $# -ne 1 ]; then

cat /etc/passwd | while read line
do
if [ echo `awk -F: '{print $3}' $line` > 500 ]; then

username = echo `awk -F: '{print $1}' $line`
temp = echo `passwd -S $username`

if [ echo `awk -F: '{print $3}' temp` ne 7 ]; then
passwd -n7 $username
fi

if [ echo `awk -F: '{print $4}' temp` ne 30 ]; then
passwd -x30 $username
fi

if [ echo `awk -F: '{print $5}' temp` ne 5 ]; then
passwd -w5 $username
fi

if [ grep -v '\/[0-9][0-9]\/[0-9][0-9]\/2003' `echo `awk $2 temp`` ]; then
echo $line
fi
fi
done

else

cat /etc/passwd | while read line
do
if [ echo `awk -F: '{print $3}' $line` >= 500 ]; then

username = echo `awk -F: '{print $1}' $line`
temp = `passwd -S $username`

if [ echo `awk -F: '{print $3}' temp` ne 7 ]; then
passwd -n7 $username
fi

if [ echo `awk -F: '{print $4}' temp` ne 30 ]; then
passwd -x30 $username
fi

if [ echo `awk -F: '{print $5}' temp` ne 5 ]; then
passwd -w5 $username
fi

if [ grep -v '^\/[0-9][0-9]\/[0-9][0-9]\/2003' `echo `awk $2 temp`` ]; then
echo $line
fi

if [ $1 = -o ]; then
echo 'Enter the command as bellow:'
echo 'l -- for disable the password'
echo 'p -- force change a users password'
echo 'f -- force change his/her passwd at next login'

if [ $1 = l ]; then
passwd -l $username
fi

if [ $1 = p ]; then
passwd -x1 -n1 $username
fi

if [ $1 = f ]
passwd -f $username
fi

fi
fi
done

fi

exit 0
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script inside shell script treotan Linux - General 4 02-19-2009 06:34 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
[SHELL SCRIPT] Write at the right of the shell window Creak Linux - General 2 04-02-2004 03:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration