User Cleanup Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting User Cleanup Script
# 1  
Old 08-01-2008
User Cleanup Script

Hi Guys, I've got an system setup to act as an sftp server. I have a script that allows me to create chroot users running a custom shell within their home directory, it also creates a subdirectory that they can write into. I'm trying to write a script (that I can cron at a later date) that checks the writeable directory for all the chroot user that have been setup.

I've got my setup script to output the usernames to a file so I end up with a file that lists all users setup for chroot (but not system users).

Also the user's home directory is setup as /home/username with the writable sub-directory being the username again (i.e. /home/username/username) I had thought it would be pretty straight forward but being a total noob it doesn't work. This is a file checker script so far:

# Script File for reading users created in SCPOnly so scan
# the writeable directories and delete files older than 7 days

for sftp in 'cat sftpuser.log' do
find /home/$sftp/$sftp/* -mtime +7 -exec rm -fr {} \
done

The script resides in the same folder as the sftpuser.log but all I get is
sftpcleanup.sh: line 8: syntax error: unexpected end of file

So, I'm obviously being a noob somewhere but a few pointers would be appreciated.
# 2  
Old 08-01-2008
Code:
find  $( cat sftpuser.log ) -type f -mtime +7 -exec rm -f {} \;

# 3  
Old 08-05-2008
Sorry, perhaps I should clarify a little more. I only want to get rid of files within the /home/username/username folders as the /username folder is a chroot jail. The files within this folder may have any name, but anything older than 7 days should be removed.

My log file lists only the user name.

I.E.

Username1
Username2
Username3
etc.

and I want to check the following folders for any file older than 7 days

/home/username1/username1/
/home/username2/username2/
/home/username3/username3/

etc.

Is this script still correct?
# 4  
Old 08-05-2008
Try this:

Code:
while read sftp
do
  find /home/"$sftp"/"$sftp"/* -mtime +7 -exec rm -fr {} \;
done < sftpuser.log

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX script for cleanup

Hello, I need some help from unix guru's here..I am looking for some advanced level script to cleanup the directories and files from specific directories under a file system.. The folders are created under /opt/modules And under modules, there are multiple subfolders with the application... (6 Replies)
Discussion started by: mb525
6 Replies

2. Shell Programming and Scripting

Suggestion with script to cleanup

I need help with sed and awk scripts to search for Symmetrix ID=000090009902 and then grep its child disk devices associated to the dead paths and display them only, so that those dead devices can be removed. test01:/#powermt display dev=all Pseudo name=hdiskpower0 Symmetrix ID=000090009902... (0 Replies)
Discussion started by: aix_admin_007
0 Replies

3. Shell Programming and Scripting

pid.cleanup script.

Hi guys! I have a directory in the production environment from which i have to delete files older then 40 minutes with .pid extention. I wrote a script below for the purpose. #!/bin/bash # # Script to delete specific file older than N minutes. # OLDERTHAN="40" #40 minutes ... (6 Replies)
Discussion started by: sajid.shah
6 Replies

4. UNIX for Advanced & Expert Users

Table Cleanup Script

I needed some help with a script to fetch and delete all records prior to 3 days from now connecting to sybase from sunos. I wrote the following script but not working..can someone please guide me with my code. Thanks #!/bin/ksh ##GET PREVIOUS DAY DATE dt=`date | awk... (3 Replies)
Discussion started by: moe458
3 Replies

5. Shell Programming and Scripting

Cleanup between parenthesis

Hi, I am trying to clean up data between parenthesis () in a file. See example below.... Input File : (New York) Chicago (London) New York (Chicago) London New York Chicago (London) (New York) (Chicago) (London) New York (Chicago) ... (3 Replies)
Discussion started by: msalam65
3 Replies

6. Shell Programming and Scripting

Mail cleanup from ksh script, keeping 50 most recent msgs

I found some posts describing how to completely clean out a mailbox in Unix/Linux. But I want to keep the 50 most recent messages. Any ideas out there? Thanks! (3 Replies)
Discussion started by: OPTIMUS_prime
3 Replies

7. Shell Programming and Scripting

Suggestions/cleanup Bash script

Hello, beginner bash scripter here.. I was able to write a script and it works just fine. I'm just wondering if someone could chime in or any suggestions to make it cleaner or tighter so to speak. I have a disk to disk backup solution which uses 250GB disks. When one gets full I just po in a new... (7 Replies)
Discussion started by: woodson2
7 Replies

8. Shell Programming and Scripting

Cleanup script

Hi! I would like to write a script which remove some files, all beginning with the same prefix : prefix.1 doc/prefix.2 ../prefix.3 etc. So, I would create a file and chmod it executable. But I dont know how to pass a variable to a script. I would like to write something like ... (2 Replies)
Discussion started by: tipi
2 Replies

9. Shell Programming and Scripting

awk/sed/ksh script to cleanup /etc/group file

Many of my servers' /etc/group file have many userid's that does not exist in /etc/passwd file and they need to be deleted. This happened due to manual manipulation of /etc/passwd files. I need to do this for 40 servers. Can anyone help me in achieving this? Even reducing a step or two will be... (6 Replies)
Discussion started by: pdtak
6 Replies

10. Shell Programming and Scripting

Help with cleanup

I am trying to add a unique string to a variable to prevent some name space collisions. DATAFILE=/u001/app/unica/affinium644/campaign/partitions/limited/tmp/ebf9aaah.t~# DATETIME=`date +%Y%m%d_%H%M%S` echo $DATAFILE > tmpnme.txt sed 's_/_ _g' tmpnme.txt > tmpnme2.txt DATA=$(cat tmpnme2.txt)... (2 Replies)
Discussion started by: whdr02
2 Replies
Login or Register to Ask a Question