Solved

awk cpu time from file

Posted on 2006-11-29
6
259 Views
Last Modified: 2010-04-21
Hi

I have this file That sometimes has one cpu reading and other times it has 2.  What I would like to do is do and awk on it then echo a line with that in it to a file and if it has 2 then  it will just echo one line then the other.

so if it had 2 cpus in the file it would do this

cpu = 5000
cpu = 2000

instead of what it does now.
cpu = 5000 2000

Here is my code

#Strips the cpu time from each run ran and adds it to a file
set runs=/pat306/acct/runs
set days=/pat306/acct/days
set cmds=$0
set pwdir=$1
set anyltype=$2
set id=$3
set server=`uname -n`
set dates=`date +%y-%m-%d-%R`
set filedate=`date +%y-%m-%d`
set user=`whoami`
echo $cmds
echo $pwdir
echo $server
echo $dates
echo $user
echo $anyltype
echo $id
echo $filedate
set cputime=`awk '/CPU/{print $6}' $pwdir/$id.dat`
echo $cputime
echo $user"  "$cputime"  "$dates" " $id"  "$server"  "$anyltype"  "$pwdir >> $runs/DoNotDeleteDaliyRun.log

Here is a sample of what I am working with  http://theyac.org/cpu.txt
The lines are TOTAL CPU TIME (SEC) =   24.800 and TOTAL CPU TIME (SEC) =   9450.7

But sometimes there will only be TOTAL CPU TIME (SEC) =   9450.7

Thanks
Bennie
0
Comment
Question by:fixitben
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 58

Expert Comment

by:amit_g
ID: 18039237
Change

echo $user"  "$cputime"  "$dates" " $id"  "$server"  "$anyltype"  "$pwdir >> $runs/DoNotDeleteDaliyRun.log

to

for cpt in "$cputime"
do
    echo $user"  "$cpt"  "$dates" " $id"  "$server"  "$anyltype"  "$pwdir >> $runs/DoNotDeleteDaliyRun.log
done
0
 
LVL 7

Author Comment

by:fixitben
ID: 18046164
When I use the above I get this
for: Command not found.
do: Command not found.
cpt: Undefined variable.

Here is my code.

#!/bin/csh
#Abaqus Acct Run Script
#Strips the cpu time from each run ran and adds it to a file
set runs=/pat306/acct/runs
set days=/pat306/acct/days
set cmds=$0
set pwdir=$1
set anyltype=$2
set id=$3
set server=`uname -n`
set dates=`date +%y-%m-%d-%R`
set filedate=`date +%y-%m-%d`
set user=`whoami`
set pwdir=/pat306/acct/scripts
echo $cmds
echo $pwdir
echo $server
echo $dates
echo $user
echo $anyltype
echo $id
echo $filedate
set cputime=`awk '/CPU/{print $6}' $pwdir/Rringstiff01.dat`
echo $cputime
for cpt in "$cputime"
do
echo $user"  "$cpt"  "$dates" " $id"  "$server"  "$anyltype"  "$pwdir >> $runs/DoNotDeleteDaliyRun.log
done

Thanks
Fixitben
0
 
LVL 58

Expert Comment

by:amit_g
ID: 18048357
You are using cshell. The syntax is different. Change

for cpt in "$cputime"
do
echo $user"  "$cpt"  "$dates" " $id"  "$server"  "$anyltype"  "$pwdir >> $runs/DoNotDeleteDaliyRun.log
done

to

foreach cpt ( "$cputime" )
    echo $user"  "$cpt"  "$dates" " $id"  "$server"  "$anyltype"  "$pwdir >> $runs/DoNotDeleteDaliyRun.log
end
0
Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

 
LVL 7

Author Comment

by:fixitben
ID: 18048456
Well it prints 2 lines but one has no cpu time and the other has both

root    06-11-30-13:56    aba5.stress.com
root  5.8400 196.99  06-11-30-13:57    aba5.stress.com


Do you know why?

Thanks
Fixitben
0
 
LVL 58

Accepted Solution

by:
amit_g earned 500 total points
ID: 18048553
Remove quotes from "$cputime" in the foreach
0
 
LVL 7

Author Comment

by:fixitben
ID: 18048700
Thanks
A million.


0

Featured Post

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question