I am trying to write a BASH script to be able to tell me the following for any given user. I.e., I would like to be able to be prompted to type in a users name in order to get the info below.
FYI, there are lots of people in these forums who will be willing to help you if you just show what you've already tried and ask a specific question.
Nobody here will do your job for you.
That being said, let me give you a couple of hints where you could start:
1) In the example
The 2nd field, indicated above as Time, I think it should be Terminal , because that's what a pts/0 is (see the line below the heading).
2) Do you really want to know the logged on time in seconds? If so, what for? Isn't the actual time (hh:mm) enough?
3) In the case that the time in the hh:mm is good, do you like the following output or still prefer the table format? (Either way, the command that was executed should give you a clue as to what you should include in your script):
When I started off with Linux and bash scripting, the most helpful book that I found is the Linux Command Line. I would suggest you download it from the book's website (it is available for free) and start reading it and doing the exercises. It will take its time, but eventually you will feel confident at writing scripts like this.
Believe it or not, I think the greater good that we can do here is to tell you to start from the beginning and build your scripting arsenal little by little :).
Good luck and let us know if you have further questions!
You have three output fields, but seem to only have two column headings. Please show us the input you're trying to process and explain (in English) what it is that you're trying to get out of it.
Note that in addition to the bad syntax on the case statement in Line 3 in your earlier posting:
Line 4: %s is not a command.
Line 5: You are missing a }, some single quotes, and a definition for the variable U.
Lines 6-9: /home/* is most likely a directory name instead an executable command; -f2 is not a valid field delimiter for cut; you have mismatched double quotes; although you appear to be trying to store the output of a pipeline into these variables, you have no command substitution; and if these problems were fixed, you don't use these variables in your script.
In you original posting in this thread, you said you wanted to be prompted for a user's name and to get information for that user. There is nothing in this script that prompts for a user name. If you intended for the script to accept a user name as an operand, your script appears to only want to do something if the user name given is "0". But, the script doesn't do that and the sample output you have shown doesn't seem to do that either.
If we can't determine what you're trying to do from the description you provide, we can't help.