0

I am writing a CGI script to monitor the system state, so the information must be outputted to the terminal with echo or cat. The problem is, systat is an interactive command, so it doesn't print anything to the screen.

I tried systat | echo and systat | cat, but the former gives nothing, whereas the latter behaves identically as systat.

Edit

OK, let me clarify. Basically, I'm asking for a shell script, say monitor.sh. When executed with ./monitor.sh, it would start a new process, output the result of systat, and then exit.

It should look something like this:

root@HPC:~/playground # ./monitor.sh
                    /0   /1   /2   /3   /4   /5   /6   /7   /8   /9   /10
     Load Average   >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 12.0

                    /0%  /10  /20  /30  /40  /50  /60  /70  /80  /90  /100
root           calc XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
root           calc XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
root           calc XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
root           calc XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
root           calc XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
root           calc XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
root           calc XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
root           calc XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
root           calc XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
root           calc XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
root           calc XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
root           calc XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
root@HPC:~/playground # 
  • What do you mean that it doesn't print anything to the screen? systat sends data to stdout when I run it on my FreeBSD machine including that of the sub-commands. – Nasir Riley Mar 14 at 4:11
  • @NasirRiley Sorry for the confusion! More precisely, I want the characters to be outputted to stdout, because this is how CGI scripts deliver content to its clients (most likely Web browsers). – nalzok Mar 14 at 13:42
  • 1
    If you are just using the systat command ny itself then it already sends everything to stdout. I'm not clear on what you're trying to do or what you are not able to achieve. Can you provide more information on what it is that you are doing and what you expect to happen? – Nasir Riley Mar 16 at 3:27
  • What happens when you just run systat from the script? – G-Man Mar 21 at 4:54
  • @G-Man The terminal window is occupied by the output of systat, until I press Ctrl + C. I guess at this time systat is running interactively – nalzok Mar 21 at 8:24
1

The man page for systat on FreeBSD says,

  • A “global” command interpreter processes all keyboard input.
  • The quit command is interpreted by the “global” command interpreter.  It tells systat to exit.
    • The quit command may be abbreviated to q.
  • “display commands” may be provided on the command line, preceded by a -.  (It is not made explicitly clear whether quit qualifies as a “display command”.)

So, it’s disappointing that systat -q doesn’t work.  Other things to try:

  • systat -quit
  • (sleep 5; echo quit) | systat
    • (You may need to enter that as sh -c '(sleep 5; echo quit) | systat'.)
    • Or you may need to do (sleep 5; echo :quit) | systat or sh -c '(sleep 5; echo :quit) | systat'.  (Note the addition of the :.)
  • systat& sleep 5; kill "$!"
    • (You may need to enter that as sh -c 'systat& sleep 5; kill "$!"'.)

You may need to adjust the sleep time to get the result that you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.