cancel
Showing results for 
Search instead for 
Did you mean: 

Abandoned files

SOLVED
Go to solution
AL_3001
Regular Advisor

Abandoned files

Hi,

We have a script to check for abandoned files on our HP-UX server. Attaching the script for reference.

Now, we are asked to assign the user and group as "root" for these files. We have abandoned files aroung 3000+ on some servers. Can someone provide a script to do this rather than doing it one file at a time.

Any input is really appreciated.

Thank You..

Regards,
Ashish A. Lahori
14 REPLIES
bright image
Frequent Advisor

Re: Abandoned files

just add this to the end of the script

for file in $(cat /var/tmp/abandoned_files.txt)
do
echo "Changing Permission of file $file to root.\n"
chown root:root $file
done

Sagar Sirdesai
Trusted Contributor

Re: Abandoned files

Check this out
find / -local \( -nouser -o -nogroup \) -exec chown root:root {} \; 2>/dev/null |grep -v "total 0"

Sagar
Dennis Handly
Acclaimed Contributor
Solution

Re: Abandoned files

You absolutely don't want to use root:root for these files. Better to make up a dummy user. You could use bin:bin.

You need to change your find so you don't invoke ls. Or you need to add -d so ll on directories don't list the files under them:
awk '{print $9}' /var/tmp/abandoned_files.txt | xargs chown bin:bin
Dennis Handly
Acclaimed Contributor

Re: Abandoned files

>bright: for file in $(< /var/tmp/abandoned_files.txt)

If lots of files, "for" may not work. No need for evil cat.

>Sagar: find / -local \( -nouser -o -nogroup \) -exec chown root:root {} \; 2>/dev/null |grep -v "total 0"

No need for that grep (ll output) and that stderr redirection. Also replace that \; with "+" for performance.
bright image
Frequent Advisor

Re: Abandoned files

just realised after seeing Dennis' reply:

the for loop should be

for file in $(awk '{print $9}'/var/tmp/abandoned_files.txt)

or the other find commands suggested will work as well - although these will have to search the filesystem again.
bright image
Frequent Advisor

Re: Abandoned files

Thanks for the reply dennis - do you know what the limit on a for loop is?
Dennis Handly
Acclaimed Contributor

Re: Abandoned files

>bright: for file in $(awk '{print $9}'/var/tmp/abandoned_files.txt)

No need for a for-loop because you can put these files on chmod directly:
chmod bin:bin
$(awk '{print $9}' /var/tmp/abandoned_files.txt)

>do you know what the limit on a for loop is?

I thought it is at least 1 Mb.
AL_3001
Regular Advisor

Re: Abandoned files

Hi Dennis,

I have made a seperate script to assign the abandoned file ownership to bin:bin. However, I get the below error:
---------------------------------
# ./aban_chk.sh
Usage: chmod [-A] [-R] [ugoa]+-=[rwxXstugo][,...] file ...
./aban_chk.sh[2]: .cshrc: not found.
---------------------------------

Attaching the script in the .txt file.

Kindly assist.

Thanks..

Regards,
Ashish

AL_3001
Regular Advisor

Re: Abandoned files

Dennis/ Gurus,

One more question, few of the abandoned files seen in file abandoned_files.txt is attached.

My question is, how do i know the absolute path of a file say i.e SDBM_File.pm .

Kindly assist.

Thanks.

Regards,
Ashish
Peter Nikitka
Honored Contributor

Re: Abandoned files

Hi,

having no absolute filename in your list, you can only guess.
You'll have to record the full pathname, when creating the list at first.
For example, change constructs like
cd /this/dir/name
find . -option ........
to
find /this/dir/name -option ...


mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
OldSchool
Honored Contributor

Re: Abandoned files

"My question is, how do i know the absolute path of a file say i.e SDBM_File.pm "

since you started find in "/", I'll bet that's where you will find the file.
AL_3001
Regular Advisor

Re: Abandoned files

Hi Gurus,

How can I search files using a find coming with date syntax in the search.

For Eg:
-------------------------------------
-rw-r----- 1 root root 814 Jun 9 1997 .cshrc
-rw-r----- 1 root root 347 Jun 9 1997 .exrc
-rw-r----- 1 root root 341 Jun 9 1997 .login
-rw-r----- 1 root root 446 Jun 9 1997 .profile
-------------------------------------

Eg: In the /var/tmp/abandonedfiles.txt file i see the above 4 files with relative path. Can i search these files with the timestspa as Jun 9 19997 in my find command?

Assistance required.

Thank You..

Regards,
Ashish A. Lahori
Dennis Handly
Acclaimed Contributor

Re: Abandoned files

>Usage: chmod [-A] [-R] [ugoa]+-=[rwxXstugo][,...] file ...

Sorry, I didn't realize the forum split the two lines. When I saw it, I assumed you would figure it out.

>how do i know the absolute path of a file

As I mentioned, you are going to have to redo that find and use "-exec ls -l -d". Or just remove -exec.

Or you can ignore them since they come from the directory and you can rescan after you chown the files.

>OldSchool: since you started find in "/", I'll bet that's where you will find the file.

No, the files would start with "/".

>Can I search these files with the timestamps as Jun 9 1997 in my find command?

Why bother? These files are repeated with the absolute path:
grep "Jun.*9.*1997.*\.cshrc" /var/tmp/abandoned_files.txt
AL_3001
Regular Advisor

Re: Abandoned files

Thanks for the advice gurus...