In the process of writing a Perl-script to submit PBS-jobs, I noticed that the output-files are only usable by the owner (rw-------). After some research, I found that you can put #PBS -W umask=002 in the job-script to make it accessible for others.
Perl:
my $client = PBS::Client->new();
my $wd = $dir_temp;
my $name = "demultiplex";
my $queue = "default";
my $wallt = "72:00:00";
my $job_demultiplex = PBS::Client::Job -> new(
wd => $wd,
queue => $queue,
name => $name,
wallt => $wallt,
cmd => "perl ".$script_directory."demultiplex.pl ".$dir_in." 2>"."demultiplex_error.log 1>"."demultiplex_output.log"
);
This Perlscript creates the following job:
#!/bin/sh
#PBS -N demultiplex
#PBS -d /store/www/labresults_QC/small_rna_sequence_analyser/data/data_temp/BGI_pilot
#PBS -q default
#PBS -l nodes=1
#PBS -l walltime=72:00:00
#PBS -W umask=002 <---
perl /store/www/labresults_QC/small_rna_sequence_analyser/scripts/demultiplex.pl /store/www/labresults_QC/small_rna_sequence_analyser/data/data_input/BGI_pilot 2>demultiplex_error.log 1>demultiplex_output.log
Is there a possibility to pass the indicated line (<---) to the job from the Perlscript?
Given the current codebase, no. You'd have to open a bug report to the PBS::Client module and request the feature. Accompany it with a patch - that might help.
Related
I'm looking for a initscript to make usage of perlbrew on a webserver running a nginx as proxy for an perl catalyst application. I'm currently trying to start the app via
source $PERLBREW
execute "perlbrew use perl-5.14.4#devel"
execute "mkdir -p $PID_PATH && $START_ICOS_APP > /dev/null 2>&1 &"
echo "$DESC started"
but it appers it cannot find the local perl installation. $PERLBREW is set to my perlbrew folder.
This is a good step by step guide how to do this, but it is French (but still understandable).
http://www.catapulse.org/articles/view/124
I copied here:
Setup the user which is going to run the catalyst app (www-data in this example)
su - www-data
curl -kL http://install.perlbrew.pl | bash
echo 'source ~/perl5/perlbrew/etc/bashrc' >> .profile
. .profile
perlbrew install perl-5.16.3 -Dusethreads --as perl-5.16.3_WITH_THREADS
perlbrew switch perl-5.16.3_WITH_THREADS
#perlbrew install-cpanm
#cpanm Catalyst Catalyst::Devel
#catalyst.pl myapp
(I assume that your application name is myapp, replace it with yours.)
create /etc/nginx/sites-enabled/myapp
server {
listen 80;
server_name exemple.com *.exemple.com;
client_max_body_size 50m;
location / {
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_NAME '';
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_pass unix:/var/www/myapp/myapp.socket;
}
location /static {
root /var/www/myapp/root;
expires 30d;
}
}
Create /var/www/myapp/myapp.fastcgi.initd
#!/usr/bin/env perl
use warnings;
use strict;
use Daemon::Control;
# 1) create initd file
# ./myapp.fastcgi.initd get_init_file > /etc/init.d/cat-myapp
#
# 3) install to runlevels
# update-rc.d cat-myapp defaults
my $app_home = '/var/www/myapp';
my $perl = 'perl';
my $program = $app_home . '/script/myapp_fastcgi.pl';
my $name = 'myapp';
my $workers = 1;
my $pid_file = $app_home . '/myapp.pid';
my $socket = $app_home . '/myapp.socket';
Daemon::Control->new({
name => $name,
lsb_start => '$nginx',
lsb_stop => '$nginx',
lsb_sdesc => $name,
lsb_desc => $name,
path => $app_home . '/myapp.fastcgi.initd',
user => 'www-data',
group => 'www-data',
directory => $app_home,
program => "$perl $program --nproc $workers --listen $socket",
pid_file => $pid_file,
stderr_file => $app_home . '/myapp.out',
stdout_file => $app_home . '/myapp.out',
fork => 2,
})->run;
Set permission on files and create the proper init file:
$ chmod +x myapp.fastcgi.initd
$ ./myapp.fastcgi.initd get_init_file > /etc/init.d/cat-myapp
Start your application and bounce your webserver:
$ /etc/init.d/cat-myapp start
$ /etc/init.d/nginx restart
I want to execute multiple commands in the same session after connecting to a server with Net::SSH::Any.
My sample code is as follows:
use strict;
use warnings;
use Net::SSH::Any;
my $host = "ip address";
my $user = "user";
my $passwd = "pass";
my $cmd1 = 'cd /usr/script';
my $ssh = Net::SSH::Any->new($host, user => $user, password => $passwd);
$ssh->system($cmd1);
my $pwd = $ssh->capture("pwd");
print $pwd;
I expected the following output:
/usr/script
but instead I am getting:
/home/user
How can I execute multiple commands in a single session?
You'll have to chain your commands in the remote shell like this:
my $cwd = $ssh->capture( q{cd /usr/script && pwd} );
You have to do it this way because even though both currently-supported backends to Net::SSH::Any provide other ways to do this (Net::OpenSSH has open2pty and Net::SSH2 has channels), the Net::SSH::Any API doesn't expose these.
For example, system invokes either Net::OpenSSH's system method or creates a Net::SSH2::Channel and invokes process('exec' => $cmd) (limited to one command per channel).
I want to edit the gitolite3`s configuration file, which is written in perl, and looks like that:
# comments
# comments
%RC = (
# ------------------------------------------------------------------
# comments
UMASK => 0077,
# comments
GIT_CONFIG_KEYS => '',
# comments
ROLES => {
READERS => 1,
WRITERS => 1,
},
# comments
ENABLE => [
# comments
'help',
'desc',
'info',
'perms',
'writable',
# comments
],
);
# ------------------------------------------------------------------------------
# comments
1;
# comments
If no augeas is available I need something that preserve the comments - they are very handy for me and future admins.
Since gitolite.rc is directly an associative array, you could consider writing your utility in perl.
src/lib/Gitolite/Rc.pm already show you how to load that file, and it provides a way to query the keys/values:
Usage: gitolite query-rc -a
gitolite query-rc [-n] [-q] rc-variable
-a print all variables and values (first level only)
-n do not append a newline if variable is scalar
-q exit code only (shell truth; 0 is success)
But you can extends those features with a way to add key/value and write the config back.
This is a shell script , How do I accomplish the same thing in Perl?
prfile=~/sqllib/db2profile
profile()
{
if [ -f $prfile ] && [ "$prfile" != "" ];
then
. $prfile
else
read -p "Enter a valid Profile : " prfile
profile
fi
}
profile
Here it checks for the profile file , if found it executes it with . $prfile else it again asks user for the proper profile file
Update
#!/usr/bin/perl
use strict;
use warnings;
my $profile = "$ENV{'HOME'}/sqllib/db2proile";
# default profile
while (not -e $profile) { # until we find an existing file
print "Enter a valid profile: ";
chomp($profile = <>); # read a new profile
}
qx(. $profile);
This worked. I want the home directory to be dynamic rather than hardcoded as they differ for different machines. I'm just trying to accomplish with Perl what I have achieved with shell.
If I understand your objectives, I don't think you can use perl to accomplish this because perl will be running as a child process and it can not change the environment of your shell (it's parent process). Maybe this would work for you (untested, off the cuff)?
prfile=~/sqllib/db2profile
if [ -s "$prfile" ] ; then
. "$prfile"
else
while true ; do
read -p "Enter a valid Profile : " prfile
if [ -s "$prfile" ] ; then
. "$prfile"
break;
fi
done
fi
from command line, how to pass a variable to coffeescript, so it can replace a corresponding placeholder, something like this:
$ echo "module.exports = {version: '$VERSION'}" | coffee -p -s VERSION=0.0.0
Expected JS:
(function() {
module.exports = {
version: '0.0.0'
};
}).call(this);
Thank you
Two things:
You need to define VERSION in the echo, not in the coffeescript compiler; by the time the coffeescript compiler sees it it's already translated $VERSION into ''.
echo is a shell builtin, and therefore the standard VERSION=0.0.0 echo "$VERSION" construct doesn't work.
So you want to create a new subshell so that the setting of VERSION doesn't propagate into your main shell, then perform the echo and coffee, like so:
$ (VERSION=0.0.0; echo "module.exports = {version: '$VERSION'}" | coffee -ps)
(function() {
module.exports = {
version: '0.0.0'
};
}).call(this);
The parentheses around the expression stop VERSION from being set:
$ echo $VERSION
$