bash/awk scripting help (creating OLD new users)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash/awk scripting help (creating OLD new users)
# 1  
Old 10-17-2006
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  
Old 10-17-2006
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  
Old 10-17-2006
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
justsam
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating new users using a text file as imput (using only shell script and/or awk)

I need somebody who could help with an exercise. You have a text file called users.txt with this info inside: users.txt: user1:1234:/home/homedir1 ; user2:1234:/home/homedir2 ; user3:1234:/home/homedir3 ; user4:1234:/home/homedir4 ; The script should create an user using the... (2 Replies)
Discussion started by: marcosruiz
2 Replies

2. UNIX for Advanced & Expert Users

Creating groups and users

Hi Could anyone please suggest how we can check in Linux if a user or a group name is already existing? In case of a user the command should also be able to specify the user with a given directory and shell. We can of course check this using a grep command but since that is just a pattern match,... (12 Replies)
Discussion started by: Dorothy
12 Replies

3. Shell Programming and Scripting

Script in bash wchich creating a new users...

Hi, I am a new on this forum but i like :) I need a script in bash which will be crating a new user with folder for websites. For example: I will run this program and he creating a new user(with my name) and folder whcich name like user and if i will localho/~user in browser, she show me files from... (1 Reply)
Discussion started by: puclavv
1 Replies

4. Shell Programming and Scripting

Creating variable using awk in bash

I would like to create a variable within my bash script using awk. I'm reading in a line from an external file, then outputting to a new file in a specific format. But, it doesnt quite work as I have expected and could use some help. (A pertinent excerpt of ) the bash code is: count=1 ... (4 Replies)
Discussion started by: snoitacilppa
4 Replies

5. Shell Programming and Scripting

bash scripting and awk help

Hey guys, i am fairly new to scripting and I am trying to write a script that takes a comma delimited file as input. I am trying to figure out a way to determine if $1 and $3 exist on a line (basically a hostname and ip address) and if true do the following, resolve the hostname to ip. sample... (6 Replies)
Discussion started by: streetfighter2
6 Replies

6. Shell Programming and Scripting

scripting help with bash and awk

I'm trying to reformat some tide information into a useable format and failing. Input file is.... 4452 CHENNAI (MADRAS) 13°06'N, 80°18'E India East Coast 01 June 2009 UT(GMT) Data Area 3. Indian Ocean (northern part) and Red Sea to Singapore 01/06/2009 00:00 0.7 m 00:20 0.7 m 00:40... (3 Replies)
Discussion started by: garethsays
3 Replies

7. Shell Programming and Scripting

help needed with creating challenging bash script with creating directories

Hi, Can someone help me with creating a bash shell script. I need to create a script that gets a positive number n as an argument. The script must create n directories in the current directory with names like map_1, map_2 etcetera. Each directory must be contained within its predecessor. So... (7 Replies)
Discussion started by: I-1
7 Replies

8. Shell Programming and Scripting

Bash and Awk for creating directories and moving files

I have a security system that FTPs the camera files to my machine, however I want to sort the pictures (taken every 30s) into directories by hour. Every picture uses the following file format. yymmddhhmmsstt.jpg (where tt is the milliseconds) I am thinking the for loop is best for file... (11 Replies)
Discussion started by: Kiint
11 Replies

9. HP-UX

creating users

hi, can any one help in how to get the numeric user id through useradd command ?? or any other command for the same?? (1 Reply)
Discussion started by: vishwaraj
1 Replies

10. UNIX for Dummies Questions & Answers

Creating Users!!!!

Can any body show me how to create users......... Thnx.... (1 Reply)
Discussion started by: ocpguy
1 Replies
Login or Register to Ask a Question