Results 1 to 5 of 5

Thread: Linux bash script with the command w

  1. #1
    Join Date
    Mar 2010
    Posts
    182

    Linux bash script with the command w

    Hello,
    I try to make a script to count the points jcpu was obtained from the command w.
    For that I have this code
    This is the bash code
    Code:
    / bin / bash
    w | awk-f utils.awk
    And utils.awk:
    Code:
    N> 2 {
        i = N - 1
        name[i] = $1
        jcpu[i] = $6
    }
    I want to use name [i], and jcpu [i] outside. Awk, but I can not. I must get out of. Awk, perhaps with a print, but despite several attempts, I have not managed to find a solution. If you guys have a solution for this then please let me know I am the interested one here. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    356

    Re: Linux bash script with the command w

    Hello,
    I think i know the answer for your question, but already a good shot in the man you show that "w-h" will have the figures.
    Code:
    w-h | awk '(print $ 6)'
    Then just count the time forgetting to convert everything into seconds and it should pass. I have no idea about the necessary function but I do so very dirty, a regexp that looks for the letter s in the result or the letter m and if it is in hours. All in a file awk if you really want.

  3. #3
    Join Date
    Dec 2009
    Posts
    296

    Re: Linux bash script with the command w

    Hello,
    I think I have a similar kind of a problem and I am trying a similar code for doing the same. I must count the points jcpu per user, or usefulness of the name [i]. Then I must use name [i], jcpu [i] in my script to make additions, subtractions with. I would like to use name [i] and jcpu [i] in my. Sh and not put them in a file share.

  4. #4
    Join Date
    Nov 2009
    Posts
    518

    Re: Linux bash script with the command w

    Hello,
    See if the following script helps you
    Code:
    / bin / bash
    
    x=0
    
    'w' | while true
    do
    	read ln # Reads one ln
    	if [ "$ ln" = "" ] # If the ln is empty
    	then
    		exit # We leave the loop
    	else
    		set -- $ ln # Break the ln parameters $ 1, $ 2, etc..
    		name[x]=$1
    		jcpu[x]=$6
    		let x=$ x+1 # Increment x
    	fi
    done

  5. #5
    Join Date
    Nov 2009
    Posts
    335

    Re: Linux bash script with the command w

    Hello,
    Actually we see your complete script (with displays after the loop, etc.)? Otherwise it is rather one-dimensional arrays as variables, to display the contents of a box, it must give its index.
    Code:
    echo ${name[0]} # Print the contents of the first cell of the table name 
    with the first term recovery of the first line of control w ...
    I hope this will help you and if you have any more problem regarding this topic then you can post here and we will try to solve your problems.

Similar Threads

  1. How to create CGI script in bash?
    By Mulan in forum Software Development
    Replies: 5
    Last Post: 01-09-2010, 08:19 PM
  2. Linux bash script for telnet connection
    By Rubero in forum Software Development
    Replies: 5
    Last Post: 23-08-2010, 09:08 PM
  3. Create bash script for ftp
    By teenQ in forum Operating Systems
    Replies: 4
    Last Post: 04-03-2010, 07:37 PM
  4. LINUX Script/Command Issues
    By Afznotermi in forum Software Development
    Replies: 5
    Last Post: 31-10-2009, 09:17 AM
  5. Bash script if then else help
    By Unix'EM in forum Software Development
    Replies: 3
    Last Post: 18-08-2009, 06:34 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,008,759.54747 seconds with 17 queries