fixitben
asked on
awk cpu time from file
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
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.
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
ASKER
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
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.
done
Thanks
Fixitben
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
for cpt in "$cputime"
do
echo $user" "$cpt" "$dates" " $id" "$server" "$anyltype" "$pwdir >> $runs/DoNotDeleteDaliyRun.
done
to
foreach cpt ( "$cputime" )
echo $user" "$cpt" "$dates" " $id" "$server" "$anyltype" "$pwdir >> $runs/DoNotDeleteDaliyRun.
end
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
A million.
A million.
echo $user" "$cputime" "$dates" " $id" "$server" "$anyltype" "$pwdir >> $runs/DoNotDeleteDaliyRun.
to
for cpt in "$cputime"
do
echo $user" "$cpt" "$dates" " $id" "$server" "$anyltype" "$pwdir >> $runs/DoNotDeleteDaliyRun.
done