convenience functions defined in /usr/share/myplc/bashrc
[myplc.git] / bashrc
1 # -*-sh-*-
2 # this file defines a few convenience bash shorthands for managing myplc nodes
3 # it is installed in /usr/share/myplc/aliases
4 # you might wish to use it in your own bash startup files (.profile/.bashrc)
5
6 ssh_options="-o BatchMode=yes -o StrictHostKeyChecking=no"
7
8 function node_key () {
9     key="$1"; shift
10     hostname="$1"; shift
11     echo Running "$@" on root@"$hostname"
12     ssh $ssh_options -i "$key" "root@$hostname" "$@"
13 }
14
15 function nodes_key () {
16     key="$1"; shift
17     filename="$1"; shift
18     for hostname in $(grep -v '#' $filename); do
19         node_boot "$hostname" "$key" "$@"
20     done
21 }
22
23 function node_dbg () {
24     [[ -z "$@" ]] && { echo "Usage: $0 hostname [command]" ; return 1; }
25     node_key /etc/planetlab/debug_ssh_key.rsa "$@"
26 }
27 function node_boot () {
28     [[ -z "$@" ]] && { echo "Usage: $0 hostname [command]" ; return 1; }
29     node_key /etc/planetlab/root_ssh_key.rsa "$@"
30 }
31
32 function nodes_dbg () {
33     [[ -z "$@" ]] && { echo "Usage: $0 hosts_file [command]" ; return 1; }
34     node_keys /etc/planetlab/debug_ssh_key.rsa "$@"
35 }
36 function nodes_boot () {
37     [[ -z "$@" ]] && { echo "Usage: $0 hosts_file [command]" ; return 1; }
38     nodes_key /etc/planetlab/root_ssh_key.rsa "$@"
39 }
40
41 function clear_keys () {
42     for hostname in "$@"; do    
43         sed -i "/$hostname/d" ~/.ssh/known_hosts
44     done
45 }
46