# show mini help
$ perl ssh_task.pl
# show registered servers generated by ./servers.conf
$ perl ssh_task.pl --server-list
# show registered general tasks generated by ./tasks.conf
$ perl ssh_task.pl --task-list
# execute registered command for registered remote servers or server labels
$ perl ssh_task.pl my_server_01 my_secret_command_01
$ perl ssh_task.pl my_favorit_servers my_secret_command_01
# execute registered command for all registered servers
$ perl ssh_task.pl all my_secret_command_02
# execute given remote command
$ perl ssh_task.pl my_server_01 do "uname -a"
# execute given remote command as sudo
$ perl ssh_task.pl my_server_01 do_sudo reboot
$ git clone https://github.com/adokoy001/Perl-SSH-Task.git ./my_ssh_task
$ cd my_ssh_task
$ vim tasks.conf
#{
# server_info => [
# ["hostname"],
# ["uname -a"],
# ["ifconfig"],
# ["free"],
# ["cat /proc/cpuinfo | grep processor"],
# ["uptime"]
# ],
# upgrade_apt => [
# [ {stdin_data => "$servers->{$server_name}->{password}\n"} ,
# "sudo -Sk -p '' "."apt-get update"],
# [ {stdin_data => "$servers->{$server_name}->{password}\n"} ,
# "sudo -Sk -p '' "."apt-get upgrade -y"]
# ],
# .
# .
# .
#}
Define tasks into tasks.conf as shown as(Perl style). It should be array reference of array reference.
You can execute any command with sudo by using stdin_data option and password parameter $servers->{$server_name}->{password}
.
$ vim servers.conf
#{
# my_server_name_01 => {
# label => ['any_label','internal','development','my_favorite'],
# host => 'localhost',
# port => 22,
# user => 'myname',
# password => 'mypassword',
# sudo_password => 'sudo_mypassword',
# general_task => {
# server_info => 'server_info',
# upgrade => 'upgrade_apt',
# reboot => 'reboot'
# },
# specified_task => {
# test_1 => [["~/.plenv/shims/perl -v"]],
# test_1 => [["~/.plenv/shims/perl global"]]
# }
# },
# .
# .
# .
#}
Configure servers.conf.
- label : You can select target servers a given label at execute.
- host : hostname or IP address
- port : SSH port
- user : login user name
- password : login password. Set undef or delete this key when you use public key authentication.
- sudo_password : password for sudo.
- general_task : Named available task from tasks.conf
- specified_task : Literally defined tasks only for this server
$ vim config.conf
#{
# max_fork_num => 20,
# servers_conf_file => './servers.conf',
# tasks_conf_file => './tasks.conf',
# StrictHostKeyChecking => 'yes',
#}
- max_fork_num : Maximum number of simultaneous processing
- servers_conf_file : Config file name for servers
- tasks_conf_file : Config file name for tasks
- StrictHostKeyChecking : Useful but dangerous OpenSSH option. If this value set
no
, warning for first time ssh connection will be ignored and '~/.ssh/known_hosts' will be updated automatically.
$ cpanm --installdeps .