1.

Solve : Help Writing Scripts?

Answer»

I am very new to Unix but I am learning. I am working on script writing. I know a lot of perl but as far as bash and awk and all the other scripting languages that is what I am trying to learn.

I want to create a script that when it is RAN it will execute the last command to display who has logged into my SYSTEM. I want to capture all these users and display how many times they have logged in.

What is the best language to use and where do I begin. I need some help getting started. I am completely lost.

Thank youYou know a lot of Perl, so why don't we start from there. It is mentioned you need to use the last command to display users logged in. therefore, you can use Perl's system CALL commands to call the "last" command.
see : perldoc -f system

Besides using system() command in Perl, there are also others like, exec. Please read up your Perl documentation for further INFORMATION. You would also need to get the results of those system calls to a variable or something for displaying the output, so i will leave it to you to find out how.

Alternatively, just use the shell plus some other text tools, such as cut , sort, uniq etc to find how many users logged in
One example.
Code: [Select]last | cut -f1 -d" "|sort -u

The above is just to show you how you can chain up useful shell tools to do what you want. For me, I would just use awk
Code: [Select]last | awk '!_[$1]++{print $1}'
could you explain the awk a little more. I am just trying to spread my wings with scripting lanuages. I do not know any bash c shell or anything of that sort and I believe it will be helpful to learn. How would I store the output to a variable?

Thank youQuote from: Circuit_Girl on March 19, 2009, 08:02:03 PM

could you explain the awk a little more. I am just trying to spread my wings with scripting lanuages. I do not know any bash c shell or anything of that sort and I believe it will be helpful to learn. How would I store the output to a variable?

Thank you
don't use C shell. use bash if you can. how to store variable
Code: [Select]var=$(last | .....)
or
Code: [Select]var=`last | .....` #note the backticks, not single quote
anyway,please look at my signature for bash scripting guide, as well as some awk resources.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 experimenting with perl and awk right now but I am not eliminating other options.

Thank you awk is a pattern recognition language. It is very powerful. I recommend PURSUING it, but I'd spend a little more time with shell script commands. Get used to how you can use them before you go on to awk.I was going to use find. If I am in a directory bla/bla/crap and I want to start my search from the root how do I do that? is it find / -name myusername ? How do I count all of them?Quote from: Circuit_Girl on March 19, 2009, 07:03:08 PM
I am very new to Unix but I am learning. I am working on script writing. I know a lot of perl but as far as bash and awk and all the other scripting languages that is what I am trying to learn.

Thank you

You may want to to the following bash web site to get some education on bash scripting. http://www.bashscripts.org/


Discussion

No Comment Found