Scripting in Unix - Need Help Starting to Write Script that track Logins
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want to see who owns more files me or root? I do not want to include directories in my search. I want it to output two lines...root (# of files) myusername (# of Files). What command tells who owns a file? and where is a good place to start?
I am thinking find \ -name root ... but I do not know how to start from the root in the file tree and I do not know how to count them.
I want to see who owns more files me or root? I do not want to include directories in my search. I want it to output two lines...root (# of files) myusername (# of Files). What command tells who owns a file? and where is a good place to start?
I am trying unix command: find -user but I do not know how to count them and do both my files and root at the same time. I also want to do others can I check them If I am not the owner?
I want to see who owns more files me or root? I do not want to include directories in my search. I want it to output two lines...root (# of files) myusername (# of Files). What command tells who owns a file? and where is a good place to start?
I am trying unix command: find -user but I do not know how to count them and do both my files and root at the same time. I also want to do others can I check them If I am not the owner?
Thank you
Why ? I.e. what bad is going to happen if you first find files owned by root and then by a non-root user ?
I am trying to experiment I am doing this but I want to leave out directories in the count and block devices...I do not want the count to include /dev and /proc. I have been experimenting with -prune but can not get it to work.
I am trying to experiment I am doing this but I want to leave out directories in the count and block devices...I do not want the count to include /dev and /proc. I have been experimenting with -prune but can not get it to work.
Very dirty, with the double-greps. Check the MAN pages on the find command, it will explain what the -type option does. Also pay particular attention to the -iregex flag. Regular expressions are VERY handy to know, and are useful not only in Perl, but alot of 'regular' Linux commands. The regex can be used to filter out the things you don't want to see....
Very dirty, with the double-greps. Check the MAN pages on the find command, it will explain what the -type option does. Also pay particular attention to the -iregex flag. Regular expressions are VERY handy to know, and are useful not only in Perl, but alot of 'regular' Linux commands. The regex can be used to filter out the things you don't want to see....
I am working on a new script that compares two files. The two files are list of users from two different groups. The scripts should look for common userids and print out one per line the userids common in the two files as well as the user numbers for those id's in each list.
The output should find user names that are similar between the two files and print them in an output to the screen. Output two other columns (machine number of the first file) (machine number of second file). So the script would find jdoe and apache similar and print the 3rd field in each file.
Something like....
I am working on a new script that compares two files. The two files are list of users from two different groups. The scripts should look for common userids and print out one per line the userids common in the two files as well as the user numbers for those id's in each list.
Any help I would greatly appreciate..Super stumped.
Thank you
Sticking with Perl, you need to check out the Array::Compare and List::MoreUtils:airwise modules from CPAN. Map will also work, and will probably prove to be much faster as well, although with smaller files, the different will be negligible.
Some examples:
Code:
use List::MoreUtils q=pairwise=;
my @a = ( 1, 2, 4, 5, 3 );
my @b = ( 1, 2, 4, 2, 3 );
my @c = pairwise { $a == $b ? 1 : 0 } @a, @b;
print "@c";
This assumes the input is two arrays, "1,2,4,5,3" and "1,2,4,2,3". If they match, print a 1. If they don't, print a 0. Output will be "1 1 1 0 1" Define your first file as array @a, second as @b. A quick bit of research will tell you how to get a file into an array..don't want to spoil all the fun. And if you look on CPAN for that module, you'll fine very complete notes on it, and how it's chewing things up on the @c line.
If you use map, you can omit the "use List..." line. From the notes on map:
Quote:
Evaluates the BLOCK or EXPR for each element of LIST (locally setting $_ to each element) and returns the list value composed of the results of each such evaluation. Evaluates BLOCK or EXPR in a list context, so each element of LIST may produce zero, one, or more elements in the returned value
I do not understand the examples listed. I am trying to find the users that are common in two files (these files are the password files) with a machine number that is the third field on a specific line. I only want to print the users that are in both list.
I do not understand the examples listed. I am trying to find the users that are common in two files (these files are the password files) with a machine number that is the third field on a specific line. I only want to print the users that are in both list.
Right. The example above takes two arrays, and compares them, which is what you want to do...print a 1 if the array elements are the same, a 0 if not. That's easily modified to print whatever, if whatever element of the array, matches an element of the other array. Check out the modules I mentioned...they're worth playing with.
However, you COULD do this with shell commands too:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.