The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 10-17-2006
justsam
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Hi Jukai,

Completing Yogesh's relpy....

#! /bin/sh

#Get the list of users in home directory
LIST=`ls -l /home | awk '{print $9}'`

#Find the users who have a user-id greater than 500
for USER in $LIST
do
USER_ID=`/usr/bin/id ${USER} | cut -f1 -d '(' | cut -f2 -d'='`
if [ ${USER_ID} -gt 500 ]
then
SUCC_LIST=`echo "${SUCC_LIST} ${USER}"`
fi
done

#Delete the files which are older than 5 days for the above collected users
for USR in ${SUCC_LIST}
do
/usr/bin/find /home/${USR} -name ",*" -type f -mtime +5 -exec /bin/rm -f {};
done


Note: Remember the above script deletes only files but not directories... for that u can modify the last find command accordingly....

Last edited by justsam; 10-17-2006 at 06:58 AM.. Reason: Small change required to the last for loop