Sponsored Content
Top Forums Shell Programming and Scripting Help Reading from Command Like vmstat Post 302472515 by palsevlohit_123 on Wednesday 17th of November 2010 10:10:47 AM
Old 11-17-2010
Step 1:
Create a perl script to display the time and the output.

Filename : dispTime.pl

Code:
#!/usr/bin/perl
while (<>) { print localtime() . ": $_"; }

Step2:
chmod 755 dispTime.pl

Step3:
Execute any command and pipe the above perl script. See the output now :-)

ex:
$ vmstat 1 5 | dispTime.pl
Wed Nov 17 10:12:06 2010: kthr memory page disk faults cpu
Wed Nov 17 10:12:06 2010: r b w swap free re mf pi po fr de sr m0 m1 m2 m9 in sy cs us sy id
Wed Nov 17 10:12:06 2010: 0 0 0 18427800 7747944 59 488 47 3 3 0 0 4 3 3 1 479 4262 1344 1 3 96
Wed Nov 17 10:12:07 2010: 0 0 0 9142184 449832 124 200 0 0 0 0 0 0 0 0 0 465 1334 1160 0 2 98
Wed Nov 17 10:12:08 2010: 0 0 0 9142184 449832 4 4 0 0 0 0 0 0 0 0 0 378 935 884 0 1 98
Wed Nov 17 10:12:09 2010: 0 0 0 9142184 449832 4 4 0 0 0 0 0 0 0 0 0 389 1035 889 0 1 98
Wed Nov 17 10:12:10 2010: 0 1 0 9142184 449832 4 4 0 0 0 0 0 1 1 1 0 421 7476 1529 1 10 90
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Reading the output of df command

Can any body please explain the following df command to me:filesystem kbytes used avail capacity mounted on /dev/root 6474195 2649052 3825143 41% / /dev/stand 24097 5757 18340 24% /stand /proc 0 0 0 ... (7 Replies)
Discussion started by: nervous
7 Replies

2. UNIX for Dummies Questions & Answers

Does command for reading from memory exist?

Does exist in unix any command which could read data from any memory address or port and return result on screen? (2 Replies)
Discussion started by: linuxchemist
2 Replies

3. Shell Programming and Scripting

VMSTAT script / command help

Hello all, I know it can be done but don't know the command. I would like to run vmstat via cron, I don't know a good interval and don't want huge logs but want stats pretty often. Please someone who uses vmstat via cron let me know what your script looks like. Thank you (11 Replies)
Discussion started by: komputersman
11 Replies

4. UNIX and Linux Applications

Reading values from the command line

Hi I want to give the user the choice of whether or not they want to include a certain option when they run the script. This is my getops: while getopts " s: d: r f: e h " option do case $option in f ) dsxfile="$OPTARG";; d ) dbname="$OPTARG";; s ) dsn="$OPTARG";; r )... (0 Replies)
Discussion started by: ladyAnne
0 Replies

5. Shell Programming and Scripting

egrep -w command by reading from file

Dear All, I want to get the rows from file1.txt whose first column is exactly as the numbers (not subset) from file1.txt. so, i have to read by line from file1.txt and search in file2.txt. So the first column of the output must be the same as the file1.txt. I used % egrep -w -f... (5 Replies)
Discussion started by: senayasma
5 Replies

6. Shell Programming and Scripting

Reading command options one by one

Hi, Just some questions on the script below...? Given: bash-2.03$ command -a option1 name1 name2 ParseOptions() { local Len=${#@} local Ctr=2 #always start at 2 local Name=() local Iter=0 while ; do if <- Is this correct? so I can get the $2... (2 Replies)
Discussion started by: h0ujun
2 Replies

7. Shell Programming and Scripting

help with reading command line into array

set -A title set -A author count=1 index=0 while do read -A ${title}?"Booktitle: " read -A ${author}?"Author(s): " (( count = count + 1 )) (( index = index + 1 )) done Hi... (1 Reply)
Discussion started by: bjhum33
1 Replies

8. Shell Programming and Scripting

Error in reading the output from command

I getting error as test1.sh: syntax error at line 3: `do' unexpected while i was trying to run below code.. What was going wrong here? find /usr/tmp/SB/reports/ -type f -name *.rdf |read file;do echo "Copying $file to /usr/tmp/SB1" done (1 Reply)
Discussion started by: millan
1 Replies

9. UNIX for Dummies Questions & Answers

Help with reading and calling a command in a script

The problem I am having now is calling and reading a command and The Main script reads the data file and passes the input to the two calculation scripts, and than output to a file. 1. The Main Script ----------------- input=inputfilepj3 output=outfilepj3 echo "*** Converting... (2 Replies)
Discussion started by: TheUnitedOSI
2 Replies

10. Shell Programming and Scripting

Reading from file bash command

Hello, I have a file in the following format id sample platform R1 R2 gene1 gene2 gene3 1 abc llumina R1_001.fastq.gz R2_001.fastq.gz apoe prnpp asp 2 def llumina R1_001.fastq.gz R2_001.fastq.gz apoe prnpp 3 ghi llumina ... (3 Replies)
Discussion started by: nans
3 Replies
FUNCTION::CTIME(3stap)					      Time utility functions					    FUNCTION::CTIME(3stap)

NAME
function::ctime - Convert seconds since epoch into human readable date/time string SYNOPSIS
ctime:string(epochsecs:long) ARGUMENTS
epochsecs Number of seconds since epoch (as returned by gettimeofday_s) DESCRIPTION
Takes an argument of seconds since the epoch as returned by gettimeofday_s. Returns a string of the form "Wed Jun 30 21:49:08 1993" The string will always be exactly 24 characters. If the time would be unreasonable far in the past (before what can be represented with a 32 bit offset in seconds from the epoch) an error will occur (which can be avoided with try/catch). If the time would be unreasonable far in the future, an error will also occur. Note that the epoch (zero) corresponds to "Thu Jan 1 00:00:00 1970" The earliest full date given by ctime, corresponding to epochsecs -2147483648 is "Fri Dec 13 20:45:52 1901". The latest full date given by ctime, corresponding to epochsecs 2147483647 is "Tue Jan 19 03:14:07 2038". The abbreviations for the days of the week are 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', and 'Sat'. The abbreviations for the months are 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', and 'Dec'. Note that the real C library ctime function puts a newline (' ') character at the end of the string that this function does not. Also note that since the kernel has no concept of timezones, the returned time is always in GMT. SystemTap Tapset Reference June 2014 FUNCTION::CTIME(3stap)
All times are GMT -4. The time now is 08:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy