1748235 Members
3582 Online
108759 Solutions
New Discussion юеВ

Re: 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 14
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