line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Interface::Shell::Csh; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
13
|
use v5.12.5; |
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.3'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use Rex::Interface::Shell::Base; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
13
|
1
|
|
|
1
|
|
44
|
use base qw(Rex::Interface::Shell::Base); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
648
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
17
|
0
|
|
0
|
|
|
|
my $proto = ref($class) || $class; |
18
|
0
|
|
|
|
|
|
my $self = $proto->SUPER::new(@_); |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
bless( $self, $class ); |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub path { |
26
|
0
|
|
|
0
|
0
|
|
my ( $self, $path ) = @_; |
27
|
0
|
|
|
|
|
|
$self->{path} = $path; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub source_global_profile { |
31
|
0
|
|
|
0
|
0
|
|
my ( $self, $parse ) = @_; |
32
|
0
|
|
|
|
|
|
$self->{source_global_profile} = $parse; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub source_profile { |
36
|
0
|
|
|
0
|
0
|
|
my ( $self, $parse ) = @_; |
37
|
0
|
|
|
|
|
|
$self->{source_profile} = $parse; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub set_locale { |
41
|
0
|
|
|
0
|
0
|
|
my ( $self, $locale ) = @_; |
42
|
0
|
|
|
|
|
|
$self->{locale} = $locale; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# sub set_env { |
46
|
|
|
|
|
|
|
# my ( $self, $env ) = @_; |
47
|
|
|
|
|
|
|
# my $cmd = undef; |
48
|
|
|
|
|
|
|
# |
49
|
|
|
|
|
|
|
# die("Error: env must be a hash") |
50
|
|
|
|
|
|
|
# if ( ref $env ne "HASH" ); |
51
|
|
|
|
|
|
|
# |
52
|
|
|
|
|
|
|
# while ( my ( $k, $v ) = each($env) ) { |
53
|
|
|
|
|
|
|
# $cmd .= "setenv $k \"$v\"; "; |
54
|
|
|
|
|
|
|
# $self->{env_raw} .= "$k $v"; |
55
|
|
|
|
|
|
|
# } |
56
|
|
|
|
|
|
|
# |
57
|
|
|
|
|
|
|
# $self->{env} = $cmd; |
58
|
|
|
|
|
|
|
# } |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub exec { |
61
|
0
|
|
|
0
|
0
|
|
my ( $self, $cmd, $option ) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
if ( exists $option->{path} ) { |
64
|
0
|
|
|
|
|
|
$self->path( $option->{path} ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# if ( exists $option->{env} ) { |
68
|
|
|
|
|
|
|
# $self->set_env( $option->{env} ); |
69
|
|
|
|
|
|
|
# } |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $complete_cmd = $cmd; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# if we need to execute without an sh command, |
74
|
|
|
|
|
|
|
# use the format_cmd key |
75
|
0
|
0
|
|
|
|
|
if ( exists $option->{no_sh} ) { |
76
|
0
|
|
|
|
|
|
$complete_cmd = $option->{format_cmd}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
if ( exists $option->{cwd} ) { |
80
|
0
|
|
|
|
|
|
$complete_cmd = "cd $option->{cwd} && $complete_cmd"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
0
|
|
|
|
if ( $self->{path} && !exists $self->{__env__}->{PATH} ) { |
84
|
0
|
|
|
|
|
|
$complete_cmd = "set PATH=$self->{path}; $complete_cmd "; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
if ( $self->{locale} ) { |
88
|
0
|
|
|
|
|
|
$complete_cmd = "set LC_ALL=$self->{locale} ; $complete_cmd "; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
if ( $self->{source_profile} ) { |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# csh is using .login |
94
|
0
|
|
|
|
|
|
$complete_cmd = "source ~/.login >& /dev/null ; $complete_cmd"; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
|
if ( $self->{source_global_profile} ) { |
98
|
0
|
|
|
|
|
|
$complete_cmd = "source /etc/profile >& /dev/null ; $complete_cmd"; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
0
|
0
|
|
|
|
|
if ( exists $self->{__env__} ) { |
102
|
0
|
0
|
|
|
|
|
if ( ref $self->{__env__} eq "HASH" ) { |
103
|
0
|
|
|
|
|
|
for my $key ( keys %{ $self->{__env__} } ) { |
|
0
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
my $val = $self->{__env__}->{$key}; |
105
|
0
|
|
|
|
|
|
$val =~ s/"/"'"'"/gms; |
106
|
0
|
|
|
|
|
|
$complete_cmd = " setenv $key \"$val\" ; $complete_cmd "; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
else { |
110
|
0
|
|
|
|
|
|
$complete_cmd = $self->{__env__} . " $complete_cmd "; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# this is due to a strange behaviour with Net::SSH2 / libssh2 |
115
|
|
|
|
|
|
|
# it may occur when you run rex inside a kvm virtualized host connecting to another virtualized vm on the same hardware |
116
|
0
|
0
|
|
|
|
|
if ( Rex::Config->get_sleep_hack ) { |
117
|
0
|
|
|
|
|
|
$complete_cmd .= " ; set f=\$? ; sleep .00000001 ; exit \$f"; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# rewrite the command again |
121
|
0
|
0
|
|
|
|
|
if ( exists $option->{format_cmd} ) { |
122
|
0
|
|
|
|
|
|
$complete_cmd =~ s/\{\{CMD\}\}/$cmd/; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
return $complete_cmd; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |