Shell script that lists files with different owner than the folder
Hello, I'm trying to write a script which is listing files based on different preferences, like filetype or permissions. All is fine, except for one: I want to list files in /home which has a different owner than the home directory it is in.
Here is an example:
/home/UserA is the directory, and /home/UserA/foobar.txt is the file, that is owned by UserB.
If I would have to use a fixed user, this wouldn't be a problem, as I could just do
But I don't know, how can I use variables, that modifies the output and the checking based on who's home directory (for a /home/UserB/foobar.txt owned by UserA scenario) it is in. I was thinking about using awk to get the owner of the home directory and the file and compare it, but it doesn't feel right.
Basically I just have to find a way, to cycle through the home directories and replace the 3 UserA in my script, like this:
Yes, like this, but my main problem is processing the folderlist in /home, because the script should work in any enviroment, not just with predefined names.
This:
would get a owners list for me, or with
I could get a list of folders (and files, but this is irrelevant in this case), but as I mentioned my problem is how to precess and use that list.
Sorry, that I left this out of my original post. I also forgot to mention, that the search has to go through every file, no matter, how deep it is in the folder tree. This is why I used 'find'.
More generic would be to get all the users in the system and then search the home directories right?
--ahamed
---------- Post updated at 02:11 PM ---------- Previous update was at 01:51 PM ----------
Following script takes the users from /etc/passwd and searches their home directory for any files which they don't own. You definitely don't want to search any system accounts. So you can update the excp_list with the users you want to skip separated by pipe.
HTH
--ahamed
Well, I was thinking about getting a userlist with
but this is messy too (extra results), and does not solve my problem. By generic I meant, that the folders in /home are not called UserA, UserB, etc. which I used in the code here.
works pretty well, I just have to find a way to insert the result into
this line, instead of UserA,...,etc.
I liked your first script better as it was less complicated for me. :-)
Using the folderlist and owners from /home is perfectly fine (I don't have to think about shares and users without home, as the focus is on those who have a home directory) and I just have to list the files that are not owned by the owner of the home directory.
I just have to find a way, to make that list usable.
I am new to shell scripting and i want to know how to execute the *.sql files from a folder through sqlplus in shell script and files should be execute in sequentially one by one while execution if any ORA error it has to exit from sqlplus session
1) scripts from external folder
2) logs has... (1 Reply)
Hi Team,
I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder.
Eg:
parent folder --> /Interface/data/test/IN
Sub folder -->/Interface/data/test/IN/Invoice20180607233338
Subfolder will be always with timestamp... (6 Replies)
I have a script that sorts and processes unsorted files to newly created directories.
Its working great, but I am trying to understand the leanest method to get the script to create an additional file within each newly created directory that:
Contains a list of all files in the directory... (4 Replies)
I am trying to copy files with specific date and name to another folder. I am very new to shell scripting so i am finding it hard to do that. see the sample code i have written below.
srcdir="/media/ubuntu/CA52057F5205720D/Users/st4r8_000/Desktop/office work/26 nov"... (13 Replies)
I have a folder (C:\shellprg\input\) containing .CSV, .zip, .gz files.
1] I want to find all .zip/.gz files from folder (C:\shellprg\input\).
2] unzip/uncompress files into the same folder (C:\shellprg\input\) through shell script.
I am using below commands for unzip files,
unzip <filename>... (2 Replies)
Hi,
I want to process all input files available into folder (C:\ShellPrg\InputFile\) Input files are abc.CSV , XYZ.zip (zip of CSV file), PQR.gz (zip of CSV file).
I want to check the extension of file, If its .zip/.gz then need to unzip the file as .CSV
I want to parse line by line of... (2 Replies)
File_A contains Strings:
a
b
c
d
File_B contains Strings:
a
c
z
Need to have script written in either sh or ksh. Derive resultant files (File_New_A and File_New_B) from lists File_A and File_B where string elements in File_New_A and File_New_B are listed below.
Resultant... (7 Replies)
Hi all,
We have some files are under 744 permissions and the the owner is say owner1 and group1.
Now we have another user owner2 of group2, owner2 can remove files of the owner1 and the permission of those files are 744, unix admin told us he did some config at his side so we can do that.
... (14 Replies)
Hi friends..
I hav a problem....
I dont know how to check .c files exists r not in a folder using IF in C shell script
actually i tried like this
if(=~ *.c)
even though some .c files or there in the current folder..it is not entering int o the if control statement...... (17 Replies)
hi all,
I need to find out the last 2 modified files in a folder.There is some way by which,we can check the timestamp and find out..??please help this is urgent.
Thanks in Advance
Anju (3 Replies)