LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-25-2021, 05:52 AM   #1
TravisBrooker
LQ Newbie
 
Registered: Jan 2008
Posts: 22

Rep: Reputation: 0
Checking permissions of files under a folder


Dear all,
i would like to put a script to check permissions,
if the file permission is only rw i want to receive an e-mail.
rw means 600,
i did something like that but it only checks folders, not the files under the folder.

#!/bin/sh
PERM=600
PARENT=/.../folder
folders=$(find $PARENT -type d ! -perm $PERM)
if [ -n "$folders" ]
then
echo "$folders" | mailx -s "smt wrong in permission" abc@xzy.com
fi

what should i do? thank you in advance.
 
Old 03-25-2021, 06:06 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
That's because it is using -type d to select only the directories. You can check the files separately using -type f
 
1 members found this post helpful.
Old 03-25-2021, 06:18 AM   #3
TravisBrooker
LQ Newbie
 
Registered: Jan 2008
Posts: 22

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Turbocapitalist View Post
That's because it is using -type d to select only the directories. You can check the files separately using -type f
Thank you very much.

i have files under a folder and under this folder for example only 1.txt permissions are 600. it means only rw. and i want to receive this notification. i want to see notification only that " there is something wrong with permission for file 1.txt"

-rw------- 1 122 Mar 21 08:49 1.txt
-rw-rw-r-- 1 82 Mar 21 08:54 2.txt
drwxrwxr-x 11 4096 Mar 25 09:01 3.txt
-rw-r--r-- 1 134406 Mar 25 10:32 4.txt

how can i able to do this?
thank you.
 
Old 03-25-2021, 07:34 AM   #4
dc.901
Senior Member
 
Registered: Aug 2018
Location: Atlanta, GA - USA
Distribution: CentOS/RHEL, openSuSE/SLES, Ubuntu
Posts: 1,005

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
Quote:
Originally Posted by TravisBrooker View Post
Thank you very much.

i have files under a folder and under this folder for example only 1.txt permissions are 600. it means only rw. and i want to receive this notification. i want to see notification only that " there is something wrong with permission for file 1.txt"

-rw------- 1 122 Mar 21 08:49 1.txt
-rw-rw-r-- 1 82 Mar 21 08:54 2.txt
drwxrwxr-x 11 4096 Mar 25 09:01 3.txt
-rw-r--r-- 1 134406 Mar 25 10:32 4.txt

how can i able to do this?
thank you.
As mentioned by Turbocapitalist, you have "-type d" which only checks directories.
Another issue I see is the "!" which is logical NOT.

For troubleshooting, breakup your tasks in 2. First just focus on the find... Once you have find working then add the notification piece...


Change this line you script
Code:
folders=$(find $PARENT -type d ! -perm $PERM)
to

Code:
folders=$(find $PARENT -perm $PERM)
Run it again, does it work?
 
1 members found this post helpful.
Old 03-25-2021, 08:35 AM   #5
TravisBrooker
LQ Newbie
 
Registered: Jan 2008
Posts: 22

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by dc.901 View Post
As mentioned by Turbocapitalist, you have "-type d" which only checks directories.
Another issue I see is the "!" which is logical NOT.

For troubleshooting, breakup your tasks in 2. First just focus on the find... Once you have find working then add the notification piece...


Change this line you script
Code:
folders=$(find $PARENT -type d ! -perm $PERM)
to

Code:
folders=$(find $PARENT -perm $PERM)
Run it again, does it work?
it worked now. thank you so much.
 
Old 03-25-2021, 08:35 AM   #6
Bonzoo
Member
 
Registered: Sep 2018
Location: Costa Rica
Distribution: Antix21a2,Parrot rolling,MXfce19.4,Sparky Openbox
Posts: 233

Rep: Reputation: 48
sudo (file manager) permissions tab
Do whatever you want in there
sudo thunar
password
opens file manager as root
permissions
GO
 
Old 03-25-2021, 12:37 PM   #7
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
I'd do it like this
Code:
find -perm 600 -exec sh -c 'printf %s\\n "$@"|mail -s "wrong perm" me@host.com' _ {} +

Last edited by shruggy; 03-25-2021 at 12:39 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy a Folder to Another Folder and Retain its Permissions voshika Linux - Newbie 2 04-26-2016 08:24 AM
Changing folder permissions and its sub folder and files? stratotak Linux - Newbie 6 12-29-2011 05:11 AM
Dependency checking this, dependency checking that. Jeebizz General 11 09-29-2009 06:51 PM
A script within a folder to delete the folder, script, and the folder's contents Cyberman Programming 15 10-17-2007 07:32 AM
permissions difference between /home/..../folder and /root/folder darkleaf Linux - General 3 07-21-2005 05:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration