![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Bash shell: Creating Preferences | airsmurf | Shell Programming and Scripting | 4 | 05-20-2008 03:49 AM |
| Creating USERs with restricted Access | ramanan25 | UNIX for Advanced & Expert Users | 4 | 05-06-2008 12:05 AM |
| creating users | vishwaraj | HP-UX | 1 | 01-14-2008 08:30 AM |
| Creating Users with SMC | chaandana | UNIX for Advanced & Expert Users | 2 | 06-26-2007 02:45 AM |
| Creating Users!!!! | ocpguy | UNIX for Dummies Questions & Answers | 1 | 12-04-2001 03:39 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
bash/awk scripting help (creating OLD new users)
I need some help making this script... I guess I'm having trouble even interpretating what to even get started on...
I need to create a script that will search a given directory (typically a user's home directory, but not necessarily) as provided on the command line and any sub-directors for temp files/directies matching the criteria (which is written below) and delete them. The only criteria are Temp file and temp directory names will begin with a comma (,). Temp files and temp directories (including all of their contents) will be removed 5 days after the last modification date of the file or directory. The home directory and all of its subdirectories, only users with user ids greater than or equal to 500 will be checked for temp files and directories. Anyone mind showing a sample script, or point me in the right direction here? I'm stumped... |
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|