Today, write a ksh script on Aix that collects Vmstat information on a regular basis and puts it into an Oracle database for query analysis, as follows:
#!/usr/bin/ksh
Export Oracle_home=/home/oracle/database
Export path= $ORACLE _home/bin: $PATH
Server_name= ' Uname-a|awk ' {print $} '
Typeset-u server_name
Export server_name
sample_time=300
While True
Todo
Vmstat ${sample_time} 2 >/tmp/msg$$
Cat/tmp/msg$$|sed 1,3d| awk ' {printf ('%s%s%s%s '%s\n%s ', $, $, $14, $, $16, $17)} '
While read Runque page_in page_out user_cpu system_cpu idle_cpu wait_cpu
Todo
$ORACLE _home/bin/sqlplus-s test/test@sid<<eof
INSERT into Test.test$vmstat values (
Sysdate,
$SAMPLE _time,
' $SERVER _name ',
$RUNQUE,
$PAGE _in,
$PAGE _out,
$USER _cpu,
$SYSTEM _cpu,
$IDLE _cpu,
0
);
EXIT
Eof
Done
Done
rm/tmp/msg$$
As a result, the tragedy occurred on the last "EOF", for the code format, I added EOF before the tab, but this is not allowed by EOF, the following error occurred:
./get_vmstat.sh[13]: 0403-057 Syntax error at line: ' < ' are not matched
EOF represents the end of this documents. Note that this is not the same as writing a C program to indent EOF to the right for beauty, because the shell stipulates that EOF must be the only occurrence of the line, not even a space. Therefore, this EOF is temporarily highlighted in this line. (This problem can be solved by changing the input operator to "<<-", but this is harmless).