Page 1 of 1
complicated question....
Posted: Wed Dec 08, 2010 8:17 pm
by Capm
Is there any way to make a script (or cronjob) or something that could log into a machine and run a command, then take the text output of that command and sort it into an mysql database from which say an MRTG graph of the data could be made?
Posted: Wed Dec 08, 2010 10:08 pm
by Jeff250
Like you said, you can schedule the task with cron.
You can login remotely into a machine and run a command with ssh (see `man ssh' for details):
ssh user@hostname command
edit: To avoid an interactive password prompt in your cron script, you will need to set up public/private key authentication (see Google for details).
With your remote command, use Unix pipes to take a first program's output as the input of a second.
You will have to write the second program, parse the inputted text with it, and insert the data into the database with it, so choose your favorite scripting language with regular expressions and MySQL bindings (python or perl would be good choices).
To make a pretty plot, you can have your second program also generate gnuplot script and then pipe that to a third program--gnuplot.
edit: Then scp (see `man scp') the plot from the remote server back locally. (You could vary this order somewhat, i.e., write the first program's output to a text file, scp that back locally, and then run the second and third programs locally, etc.)
Posted: Thu Dec 09, 2010 5:33 pm
by fliptw
depending on the format of the output, you could just run mysqlimport.
But it would make things easier to use something like python or perl.