Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dexer
02-27-2016, 11:09 AM (This post was last modified: 05-30-2018 06:59 PM by rayluk.)
Post: #1
dexer
dexer is a distributed commands via ssh
guardian: xwcwt

Design:
After reading more source code of auth, I decide to write a simple plain bash script which is more appropriate.

the default hosts(ips) configuration file is $think_base/conf/ips.cfg, one ip(hostname) one line. the command is execed in a serial way.

Param: username command
Pseudo code:
Code:
$ips?=/thinker/etc/ips.cfg
if $ips not exist then $ips=$think_base/conf/ips.cfg
if 'p'  is a parameter then pastat=True; else pastat=False
if '--shell' is a parameter then use_shell=True; else use_shell=False

if use_shell then command = bash -c "$command"

globe_rr=0

if pastat == False
  for ip in $ips
  {
           ssh -t $username@$ip "$command" && rr=$? || rr=$?
           if $rr != 0 and globe_rr=0  then $globe_rr = $rr
   }
else
  array=(for ip in $ips; do put 'ssh "$usernmae@$ip" "$command" ' into the array;done)
  prun --no-error $array[@] && globe_rr =$? || globe_rr=$?
}

if report_error == True{
   return $globe_rr
}
else{
   return 0
}


Usage:
dexer username command"
username is the user to exec the command"
command is the command to be execed, need wrapped by ""

--report-error: True/False, if this is True, return value of dexer would be the first failed command. If this is False, return value of dexer would always be zero. Default: False

Examples:

Copy a file on a number of nodes in user gene:
Code:
dexer gene "cp /mnt/dstore/gene/glad/work/lingu/F159_L2_2-1mbp.fq /mnt/fastdata/bwamem" p

Reboot a number of nodes except for tb31-2:
Code:
dexer --ips=ips.lst "if [[ \`hostname\` != tb31-2 ]] ; then reboot; fi; "

A compound command:
Code:
dexer --ips=/thinker/etc/ips.cfg 'sh -c "echo lingu dir && pwd && ls ~lingu"'


Return non-zero when some command failed
Code:
dexer --report-error=True 'mountpoint /thinker/storage' p

Maintain:
the script is relative simple, if there's any error happens or need add more func, just do ops in the source code.

-----
20160406/gl: Added another example (compound command)
20160321/gl: Add another example.
20160321/xwcwt: add example.
Quote this message in a reply
02-27-2016, 04:32 PM
Post: #2
RE: dexer
Good to have it. Will try.
Find all posts by this user
Quote this message in a reply
02-27-2016, 05:05 PM (This post was last modified: 02-27-2016 05:12 PM by lingu.)
Post: #3
RE: dexer
Need default IP list -- ips.cfg

----
[dev@tb33-1 bin]$ ./dexer "ls"
Usage:
./dexer username command
---username is the user to exec the command
---command is the command to be execed, need wrapped by ""
----

I think the code supports ips.cfg but somehow it does not work.

I will work on it.
Find all posts by this user
Quote this message in a reply
02-27-2016, 05:18 PM
Post: #4
RE: dexer
(02-27-2016 05:05 PM)lingu Wrote:  Need default IP list -- ips.cfg

----
[dev@tb33-1 bin]$ ./dexer "ls"
Usage:
./dexer username command
---username is the user to exec the command
---command is the command to be execed, need wrapped by ""
----

I think the code supports ips.cfg but somehow it does not work.

I will work on it.

username is needed. you can use the script likes:
./dexer gene "ls"
Quote this message in a reply
02-28-2016, 12:29 AM
Post: #5
RE: dexer
The code is in cod://bin
Find all posts by this user
Quote this message in a reply
03-08-2016, 11:01 PM
Post: #6
RE: dexer
An example:

Copy a file on a number of nodes in user gene:
Code:
dexer gene "cp /mnt/dstore/gene/glad/work/lingu/F159_L2_2-1mbp.fq /mnt/fastdata/bwamem" p
Find all posts by this user
Quote this message in a reply
03-20-2016, 04:49 PM
Post: #7
RE: dexer
(03-08-2016 11:01 PM)lingu Wrote:  An example:

Copy a file on a number of nodes in user gene:
Code:
dexer gene "cp /mnt/dstore/gene/glad/work/lingu/F159_L2_2-1mbp.fq /mnt/fastdata/bwamem" p

Please add this example to the headpost.

dexer should also support the ips option -- "--ops=<ipsfile>".
Find all posts by this user
Quote this message in a reply
03-21-2016, 07:40 PM
Post: #8
RE: dexer
Reboot a number of nodes except for the portal:

Code:
dexer --ips=ips.lst "if [[ \`hostname\` != tb31-2 ]] ; then reboot; fi; "
Find all posts by this user
Quote this message in a reply
03-27-2016, 03:23 PM
Post: #9
RE: dexer
dexer only searches ~/think/conf/ips.cfg for the IP list, but it does not work before the thinker is installed. Also, some users, such as root, does not install a thinker.

I suggest we add a dir /thinker/etc and store a default ips.cfg file there, and let dexer search it at a lower priority.
Find all posts by this user
Quote this message in a reply
03-27-2016, 03:24 PM
Post: #10
RE: dexer
(03-27-2016 03:23 PM)lingu Wrote:  dexer only searches ~/think/conf/ips.cfg for the IP list, but it does not work before the thinker is installed. Also, some users, such as root, does not install a thinker.

I suggest we add a dir /thinker/etc and store a default ips.cfg file there, and let dexer search it at a lower priority.

@zma pls review.
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: