Rex::Misc::ShellBlock 内容
来源:互联网 发布:mac系统xampp使用教程 编辑:程序博客网 时间:2024/06/04 01:06
# (c) Jan Gehring <jan.gehring@gmail.com># # vim: set ts=3 sw=3 tw=0:# vim: set expandtab: package Rex::Misc::ShellBlock;use strict;use warnings;use Rex::Commands;use Rex::Commands::Fs;use Rex::Commands::File;use Rex::Commands::Run;require Exporter;use vars qw(@EXPORT);@EXPORT = qw(shell_block);use base qw(Exporter);sub shell_block { my ($shebang, $code) = @_; if(! $code) { $code = $shebang; $shebang = "#!/bin/bash"; } if($shebang !~ m/^#!\//) { $shebang = "#!$shebang"; } my @lines = split(/\n/, $code); if($lines[0] !~ m/^#!\//) { # shebang not there, so add /bin/bash for default unshift(@lines, $shebang); } my $rnd_file = "/tmp/" . get_random(8, 'a' .. 'z') . ".tmp"; file $rnd_file, content => join("\n", @lines), mode => 755; my $ret = run "$rnd_file 2>&1"; my $ret_code = $?; unlink $rnd_file; $? = $ret_code; return $ret;}1;=pod=head1 NAMERex::Misc::ShellBlock - Module to execute a shell block.=head1 DESCRIPTIONThis module exports a function called I<shell_block>. This function will upload your shell script to the remote system and executes it. Returning its output as a string.=head1 EXPORTED FUNCTIONS=over 4=item shell_block($code)This function will add a default shebang of '#!/bin/bash' to your code if no shebang is found and return its output. my $ret = shell_block <<EOF; echo "hi" EOF=item shell_block($shebang, $code)This function will add $shebang to your code and return its output. my $ret = shell_block "/bin/sh", <<EOF; echo "hi" EOF=back=head1 USAGE use Rex::Misc::ShellBlock; task "myexec", sub { shell_block <<EOF; echo "hi" EOF };
阅读全文
0 0
- Rex::Misc::ShellBlock 内容
- REX。。。。。
- Rex
- rex 和 racc (二) 去掉注释的内容
- Misc
- MISC
- Misc
- MISC
- MISC
- Misc
- Misc
- misc
- MISC
- MISC
- MISC
- Misc
- misc
- misc
- 生活是如此的"fuck"
- hibernatetemplate save() 没有插入数据
- 最近做项目遇到的棘手问题
- Java中的四种引用类型
- 响应式rem介绍
- Rex::Misc::ShellBlock 内容
- 赞赏还是批评?未来的人将如何看待今天的机器人?
- 高级Java工程师面试资料收集
- bashrc备份
- 使用ndk-build脚本与排除构建系统故障
- 静态链表-数据结构(3)
- SQL SERVER 中的smalldatetime和datetime区别
- dhtml--复选框组件
- python判断输入的字符串是否是回文联