Bash script
Hello :)
I need help with bash scripting " script finds for each user(chosen users/groups) files which belong to them and other users have access to those files(optional specifically groups) and mail to user list of these files. " I dont use bash normally and in work i'm actually doing 3 large projects so i dont have enough time for doing this. Can someone help me? I know its easy for you but i'm not familar with programming and those things sorry for my english |
So what have you done so far?
This is my prefered bash reference http://tldp.org/LDP/abs/html/index.html |
I didn't even started. It's very confusing when i read about it, i had only PHP and HTML basics ;(
|
Code:
man find Hints grep /etc/passwd to find / verify a user exists, use awk to get the user id and then read about the find command. |
Quote:
Otherwise, lots of bash scripting tutorials/examples you can easily find with an internet search...much like how you found this site. And we will never do your homework for you either. |
Quote:
Quote:
The intentions of LQ are that we are not paid support, we are all volunteers and we are here to help you, but also help you to learn about Linux, not to do your effort for you. Continued behavior where you ask people to just complete your work for you may result in you not being able to participate on the LQ site. A few members have offered some means to get going, and here is another one from my blog, Bash Scripting for Dummies and Geniuses Also my favorite (self) quote: Quote:
|
#!/bin/bash
users=($(awk -F'[/:]' '{if ($3 >= 1000 && $3 != 65534) print $1}' /etc/passwd)) touch tmp for user in $users do echo "###############################################">> tmp echo "@@@@@@@@@@@@@@@@@@@@ $user @@@@@@@@@@@@@@@@@@@@">> tmp echo "###############################################">> tmp echo " ">> tmp find / -type f -user $user -perm /333 >> tmp echo " ">> tmp done this is what i made and i stucked |
Quote:
A couple of points:
|
Thanks you!
Actually my problem is that running this script with no parameters is supposed to do list of files for every "human-made" accounts so there is any way to use this script in loop to run it for every account in OS and find how to find out that someone have access to file of these accounts? I must in first step find all files which i posses and then check permissions? My goal is in the first post |
Enter the loop with the entire list of users from /etc/passwd, do not filter it down prior to entering the loop.
When inside the loop, perform your if test to determine if the id is greater than or equal to 1000. If yes, then perform the find. Otherwise, no action. I believe what your script is doing is that it takes /etc/passwd once, checks it once, finds the first occurrence of a user matching your if-test qualifications of >= 1000 && !65534, and that's it. It only ever finds the first occurrence. When you enter your for loop, you have one entry in your list. Instead make the list $users be the entirety of /etc/passwd. Enter the loop. And then perform your if-test and use that outcome to run or not run the find command. |
on my system it finds 2 users.
the script seems to be doing what it is supposed to do: find all files that belong to a certain user and spit them out. the permission thingy is new to me; i hope it finds what it is supposed to find. of course there is no mailing yet. a few points:
Code:
#!/bin/bash |
Scanning / is expensive.
I would do this once and save the output in a file. A -ls keeps the user information along with the file names. Then loop over the users and grep them in the file. Example script: Code:
#!/bin/bash |
Now it looks like this :
Code:
#!/bin/bash format of command will be someting like sh script.sh (-u or -g) (multiply or single user or groups) -c(check) (users which he want to check if they have access to his files.) (mail address) it is ok? |
All times are GMT -5. The time now is 01:25 AM. |