storing remote terminal output in a variable

Pseudo-terminal will not be allocated because stdin is not a terminal

I have been using similar script as of above for long. I login on remote devices, have some commands ran on them and then logout. I use telnet and ssh both for remote login. so far all the commands are being echo-ed to remote terminals and the output being saved to some log files. what I need is to be able to interpreter the output generated by the remote terminal. Consider following a command sent to remote terminal after successful login via SSH/Telnet:

echo "show system date"

after running above command, I want to store the output generated by remote machine in a variable and perform some if/else statements. So far, I didn't have any kind of success. can someone please guide me how I can save the output generated by remote terminal in a variable?


If ansible is an option you could register the output and based on it do some actions, for example:

- name: show system date
  command: date
  register: date

- debug: msg="{{ date.stdout }}"

You could read more about ansible and the conditionals here: http://docs.ansible.com/ansible/latest/playbooks_conditionals.html

链接地址: http://www.djcxy.com/p/97138.html

上一篇: 通过远程SSH运行完整的命令

下一篇: 将远程终端输出存储在一个变量中