简体   繁体   中英

how can i ssh into a server, and read a pid file and bring back the #?

i am tasked with Perl to ssh into another server and stop/start/restart the process if it is not already started.

i will break this down into small chunks:

::how can i ssh into a server, and read a pid file and bring back the #?::

i can do this: system("ssh serverid.gcsc.att.com -l myid -i /home/myid/.ssh/authorized_keys 'kill -9 1234'"); just fine, kill the process after authenticating into the server.

but how do i read a pid file/any file on that server, and get the value into a variable so that i can then ssh and kill the process?

Easiest way is with backticks.

 my $output = `ssh server -l myid -i /home/myid/.ssh/authorized_keys some_command`;

$output will contain the output of your ssh command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM