The UNIX and Linux Forums  


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



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-17-2006
Jukai Jukai is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 1
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...
  #2 (permalink)  
Old 10-17-2006
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
this will help you to find files whose names begin with comma:

Code:
find . -name ',*'

check the mtime option of find command, which will help you in finding files which are modified 5 days ago


Code:
id someuser

this command will show the userid of that user. you need to check if uid is greater than 500
  #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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:53 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0