I am trying to run vmstat via a bash script every 20 seconds and output the results to a file for several hours. My script looks like this:
#!/bin/bash
vmstat 20 1000 | ./timestamp.pl >> vmstat.txt
timestamp.pl script looks like this:
#!/usr/bin/perl
while(<>){
print localtime() . "$_ ";}
I am calling timestamp.pl to insert timestamp in each line of vmstat output. The script is running on SunOS for about an hour and I dont see any entry in vmstat.txt file. Any ideas why is this or any way to improve it so that it writes the output to the vmstat.txt file?
答案 0 :(得分:2)
Either wait for enough time for the perl output to be flushed (the script will end after about 5h30min) or disable buffering in your perl script by adding this line before the loop:
$|++;