Hello everyone
I really hope you can help me, I can't continue:
Im on a project to work with my Server.
I wanted to put on my server all data-systems and I did this:
The output is a string.
How can I turn the string into a table?
On the second point I wanted to see all java processes and runned this command:
Now the output has many unneccesary informations and I just want to have the CPU consumption.
How can I get the CPU consumption of each java process?
Welcome to the forum.
(and thanks for using code tags correctly in your very first post!)
The output of df -h certainly is NOT a string but a few lines of text. I guess you assigned it to a shell variable; when printing that WITHOUT proper quoting / escaping the shell (which you fail to mention) will convert all line feeds into spaces and make it seem like a single string. Try printing using double quotes.
What do you mean by "table"? DB table, HTML table, spread sheet table, text file looking like a table?
For your second question, look into man ps for OUTPUT FORMAT CONTROL and STANDARD FORMAT SPECIFIERS; in your case %cpu might help.
Hello RudiC
Nice for seeing such a nice community here.
In my case, I want a basic table like a HTML.
Sorry for not being so exactly.
And for the other point.
Thank you a thousand times, I will check this out.
---------- Post updated at 04:13 AM ---------- Previous update was at 04:11 AM ----------
Quote:
Originally Posted by RudiC
Welcome to the forum.
(and thanks for using code tags correctly in your very first post!)
The output of df -h certainly is NOT a string but a few lines of text. I guess you assigned it to a shell variable; when printing that WITHOUT proper quoting / escaping the shell (which you fail to mention) will convert all line feeds into spaces and make it seem like a single string. Try printing using double quotes.
What do you mean by "table"? DB table, HTML table, spread sheet table, text file looking like a table?
For your second question, look into man ps for OUTPUT FORMAT CONTROL and STANDARD FORMAT SPECIFIERS; in your case %cpu might help.
Hello RudiC
Nice for seeing such a nice community here.
In my case, I want a basic table like a HTML.
Sorry for not being so exactly.
And for the other point.
Thank you a thousand times, I will check this out.
I wanted to put on my server all data-systems and I did this:
The output is a string.
How can I turn the string into a table?
As RudiC already told you the output is not a string. Try the command on a command line in your terminal and you will see a nicely formatted (ASCII)-table.
The answer to your question is simple: use a shell script. I assume (because your interest in Java processes) that you have some programming background and the good news is: all the common UNIX/Linux shells have a twofold purpose. They can be used to enter commands interactively but they are also (quite powerful) language interpreters for the programming language they implement. If you have a Windows background: think of cmd.exe and powershell rolled into one.
To implement a script for your filesystems, you might want to start with selecting a better option set to df: the command you used is optimized for human reading (hence the option -h), which is not optimal for machine reading. As you might have noticed there are different units used for filesystem sizes and parsing (K)ilobytes, (M)egabytes, (G)igabytes and whatnot will make your code more complicated.
Using the -P (POSIX) switch will make that easier because only one unit (1024-byte blocks) will be used. Furthermore, POSIX is *the* UNIX standard and this way you will be able to use your script on a wide variety of UNIX systems whereas -h is only available on Linux-systems and if you use it your script will only run on Linux-systems.
Now try the command on your terminal and look at the output. Here is an example of the laptop i am writing this:
You first need to analyse which part of the information you are interested in: probably not the first line of output because this is header information. Maybe also not in filesystems of the type "tmpfs" or "udev" because these are not real filesystems, they are only created at runtime. You can filter lines with the grep command (i suggest you read the man page for it, also try the command and play around with it by changing it and observing the different outcomes), so let us try this:
OK, this is is what we are really interested in. Now we need to read the columns one by one and assign the values to variables which we will later be able to process. For this there is the shell built-in command read. The shell will split the input along whitespace itself so we don't have to do this ourselves. For instance:
As you see commands can span several lines and you still can enter them on the command line. You can also save this to a file and execute it - this is a "script"! There is no difference between what you enter on the command line and what you write in scripts - everything you use on the command line can be used in a script and vice versa.
A few things in the above command need to be explained:
this command reads a line of input (in the case above provided by the directing the output of the previous command into it, a so-called "pipeline") and splits it along whitespace. The first "word" then goes to a variable called "var1", the second word to "var2" and so on. If there are more words than variables the last variable gets all the remaining words, if there are more variables than words the last variables will be empty. In our case there are exactly as many variables as there are words and each variable gets one word.
This is a loop which is repeated as long as command (which can be any command or built-in, in our case it is the read) returns a return code of 0. Every command, when ending, sets such a return code and UNIX convention is that a return code of 0 means "success", everything else some sort of failure.
In our case the read will return 0 as long as there are input lines to read, only when there is nothing to read any more it will return non-0, which will terminate the while-loop.
A last thing about variables: when you assign them you do that:
but when you want to use them (i.e. to display them) you need to put a "$" before their name like this:
you can also surround the output of a variable by fixed text:
but in some cases where the fixed text will be characters it might be ambiguous:
This would display "foo" followed by the content of the variable varbar instead of the variable var followed by the fixed text "bar". TO remove such ambiguities use the braces:
Now, this is a rather lame excuse for a good introduction into shell programming, but i hope i have piqued your interest enough to make you start scripting. Have fun with the shell!
I have users that print files to selected printers. Instead of creating one function for each printer I would like to have just one and passing the files to print as well as the wanted printer. The following code does not work, of course.
I'm expecting that $1 is the list of files to be printed... (6 Replies)
Hi, I am complete new to C programming and shell scripting. I just wrote a simple C code to calculate integral using trapezoid rule. I am prompting user to pass me No. of equally spaced points , N , upper and lower limit. My code looks as follows so far:
#include<stdio.h>
#include<string.h>... (2 Replies)
Hi Team,
Could you please help me on below query:
I want to retrieve XML elements from one .xml file. This .xml file has commented tags as well. so i am planning to write Unix command/script which 1.will chekc for this .xml file
2. it will ignore the commented XML lines. i.e. XML tags between... (3 Replies)
Hello, and here's my problem:
I can't get my function to do what I want. When I call my function get_from_A_to_F I give it an argument $remainder. I want my function to substitute a number higher than 9 to a specific letter. If the argument is equal to 10 than it should change it to "A".... (8 Replies)
Hi All,
I am new to Unix , there i am facing one problem with sleep command. that is ..
in while loop i have defined sleep function ..
my condition is like this
while #i knew this is infinite loop
do
sleep 200
echo "hello "
done.
this condition will never become .. true... (3 Replies)
Hi,
I want to copy a file/directory ( recursively , if needed) and if destination directory does not exist create it ( with parent directory, if needed).
funcopy () {
if ; then
echo "$2 exists , copying files"
cp -r "$1" "$2"
else
echo "Directory does not exist;Create directory"
mkdir... (1 Reply)
Hello again,
Am having an issue now with getting a simple grep command to work within a function..
The function is as below...
function findRecord() {
output=grep "001" recordDatabase
echo $output
}
At the moment the "001"... (3 Replies)
Hi All,
Following is the output of a find commnd to locate log directories for various projects of UNIX AIX box:
/home/hbinz6pf/projectlibs/dpr_pfsdw_dev/&PH&
/opt/tools/ds/Template/&PH&
/data/ds/ms/hmsdw/projectlibs/dpr_ms_dev/&PH&
/data/ds/riskmi/projectlibs/dpr_riskmi_dev/&PH&... (5 Replies)
Hi All,
Following is the output of a find commnd to locate log directories for various projects of UNIX AIX box:
/home/hbinz6pf/projectlibs/dpr_pfsdw_dev/&PH&
/opt/tools/ds/Template/&PH&
/data/ds/ms/hmsdw/projectlibs/dpr_ms_dev/&PH&
/data/ds/riskmi/projectlibs/dpr_riskmi_dev/&PH&... (1 Reply)
I have written a script which does a following functions:-
1) Check a area if it is mounted or not
2) If the area is not mounted it will prompt the user to mount the are.
3) Once the area is mounted and the option is given as Y or y
the script continues...
My question is will the below... (2 Replies)