Path Tcl and Bash - bash

i have a problem with path in a tcl file i tried to use
source " /tmp/mob.tcl "
and this path in bash file :
/opt/ns-allinone-2.35/ns-2.35/indep-utils/cmu-scen-gen/setdest/setdest -v 1 -n $n -p 10 -M 64 -t 100 -x 250 -y 250 >> /tmp/mob.tcl
but terminal give me this error :
couldn't read file " /tmp/mob.tcl ": no such file or directory
while executing
"source.orig { /tmp/mob.tcl }"
someone can help me please

Learn to believe the error messages you get ;-).
couldn't read file " /tmp/mob.tcl ": no such file or directory
This is because you have submitted a string with the first letter (and the last) of the path being a " " char, i.e.
source " /tmp/mob.tcl "
try submitting
source "/tmp/mob.tcl"
IHTH

Related

GNU parallel environmental variables separated from input

I have a problem which I think should be very easy to fix, but I for some reason I cant solve it..
I am using GNU parallel inside of Snakemake to perform some variant calling.
My input file (contigs.txt) looks something like this:
GL000207.1
GL000226.1
GL000229.1
GL000231.1
GL000210.1
GL000239.1
GL000235.1
The command which ultimatly gets executes looks something like this:
"name=$(bash get_name.sh normal_recal.bam) \n"
"cat {input.contigs} | "
"env_parallel --env name --jobs {threads} "
"'({input.GATK} Mutect2 -I {input.tumor} -I {input.normal} "
"-R {input.reference} -normal $name "
"--native-pair-hmm-threads 4 "
"-L {{}} --germline-resource {input.gnomAD} "
"-O {input.path}/{wildcards.sample_id}/{{}}.somatic.vcf "
"--f1r2-tar-gz {input.path}/{wildcards.sample_id}/{{}}.f1r2.tar.gz) &> {log.err}.{{}}.err' \n"
If I execute this script in my interactive terminal every thing works as expected. However when I am trying to execute it inside snakemake, the program just ends without an error. I think I have tracked down what the problem is using this simple example:
cat contigs | env_parallel --env name --jobs 4 'echo $name'
This prints something like this:
sample_tumor GL000207.1
sample_tumor GL000226.1
sample_tumor GL000229.1
sample_tumor GL000231.1
I think that the problem is, that the input variable also gets passed to the $name variable, which causes the program to crash.
I was wondering how I can achieve, that only the the actual $name (i.e. here sample_tumor) gets passed. So the output of the above example would be
sample_tumor
sample_tumor
sample_tumor
sample_tumor
Cheers!
It turns out my guess regarding the error was wrong. I think I miss used env_parallel.
This code solved my problem.
"name=$(bash get_name.sh normal_recal.bam) \n"
"export name \n"
"cat {input.contigs} | "
"parallel --jobs {threads} "
"'({input.GATK} Mutect2 -I {input.tumor} -I {input.normal} "
"-R {input.reference} -normal $name "
"--native-pair-hmm-threads 4 "
"-L {{}} --germline-resource {input.gnomAD} "
"-O {input.path}/{wildcards.sample_id}/{{}}.somatic.vcf "
"--f1r2-tar-gz {input.path}/{wildcards.sample_id}/{{}}.f1r2.tar.gz) &> {log.err}.{{}}.err'"

Scripting telnet mailing

I want to create a script that will be able to send mail easily with the user choices.
I did this but it does not work
mail_sender ()
{
echo " - FROM : "
read from
echo " - TO : "
read to
echo " - Subject : "
read subject
echo " - Message : "
read message
telnet localhost 25
ehlo triton.itinet.fr
mail from: $from
rcpt to: $to
data
subject: $subject
$message
.
}
Do you have an idea ?
Redirect to telnet a here-document:
mail_sender ()
{
echo " - FROM : "
read from
echo " - TO : "
read to
echo " - Subject : "
read subject
echo " - Message : "
read message
telnet localhost 25 << EOF
ehlo triton.itinet.fr
mail from: $from
rcpt to: $to
data
subject: $subject
$message
.
EOF
}
The content of the here-document will be redirected to telnet, effectively executing these SMTP commands in the mail server's shell.
It's important that the lines within the here-document don't have any indentation at all (no spaces or tabs at the start of the lines).
Notice that the indentation looks kind of broken in the way I wrote it above, halfway in mail_sender. It has to be this way,
because that's how here-documents work.
You can read more about here-documents and input redirection in man bash.
I've only used it for the simplest of testing:
http://www.jetmore.org/john/code/swaks/
but it boasts:
Completely scriptable configuration, with option specification via
environment variables, configuration files, and command line
so no need to re-invent the wheel here..

Open terminal and execute command with arguments in command line mac

I am currently using :
Runtime.getRuntime().exec("open -a Terminal" + directory + " " + argument);
My argument happens to also be a directory.
My problem is that it will open argument instead of considering it an argument of directory. The outcome will be the same as running the following:
Runtime.getRuntime().exec("open -a Terminal" + directory)
and
Runtime.getRuntime().exec("open -a Terminal" + argument)
Instead of typing directly in a terminal :
$/Users/xxxxx/RestOfPath /Users/xxxxx/argument
Is there a solution which would look like this without parenthesis?
Runtime.getRuntime().exec("open -a Terminal (" + directory + " " + argument+ ")");
Thank you!
You could try escaping the space
Runtime.getRuntime().exec("open -a Terminal" + directory + "\\ " + argument);

Getting name of file inside a rar without unrar

Trying to get a bash script together, however I'm stuck at this. The rar is splited into x files, within the rar is 1 single file. What I'm doing is as below:
cd $dir
for rarfile in $(find -iname "*.part1.rar")
do
echo "Rar file: " $rarfile >> $dir/execute.log
name = $(unrar lb "$rarfile")
echo "Name of file inside rar container: " $name >> $dir/execute.log
extension ="${name##*.}"
echo "Extension: " $extension >> $dir/execute.log
filename = ${name%.*}
echo "Name: " $filename >> $dir/execute.log
# unrar x -y -o- $rarfile $uprar_dir
done
The excecute.log is as below:
Rar file: ./file.part1.rar
Name of file inside rar container:
Extension:
Name:
Cant seem to get the $name working. The unrar is however working fine as it should. Pls help.
in bash to assign value to a variable you cannot have spaces ie:
name=$(unrar lb "$rarfile")
instead of:
name = $(unrar lb "$rarfile")

script to zip a file and change it's owenrships

I have a script I am working on that reads off of a text file and will use the information stored in the text file to put each line entered in as an array. This array is a reference to files that are imported to a directory in another script. The problem is i built a function to zip the contents of the directory and change it's ownerships, but when I run the script it was zipping and attempting to change ownerships of the pwd. Here is my code below:
file=~/exporttool/zipFiles.txt
index=0
declare -a studyinstanceuids
while read line ; do
studyinstanceuids[$index]="$line"
index=$((index+1))
echo $line
done < $file
for i in "${studyinstanceuids[#]}"
do
echo "$i" | ./cmd2;
done
echo "Exams are in!";
##Function with argument that will take prompt to change ownerships
echo "What is the name of the owner: "
read $owner
zipForOwner(){
arg1=$1
for i in "${studyinstanceuids[#]}"; do
zip -r ~/export/"${studyinstanceuids[#]}"/20140620_"${studyinstanceuids[#]}".zip .
sudo chown $1:$1 ~/export/"${studyinstanceuids[#]}"/"${studyinstanceuids[#]}".zip
sudo mv ~/export/"${studyinstanceuids[#]}"/"${studyinstanceuids[#]}".zip ~/home/"$1"
done
}
zipForOwner $owner
exit;
Does anyone have any suggestions
EDIT: Heere are my results running in xterm
+ file=/home/support/exporttool/zipFiles.txt
+ index=0
+ declare -a studyinstanceuids
+ read line
+ studyinstanceuids[$index]=1.3.46.670589.16.11.8.34254330145.20140603.134057.0
+ index=1
+ echo 1.3.46.670589.16.11.8.34254330145.20140603.134057.0
1.3.46.670589.16.11.8.34254330145.20140603.134057.0
+ read line
+ for i in '"${studyinstanceuids[#]}"'
+ echo 1.3.46.670589.16.11.8.34254330145.20140603.134057.0
+ ./cmd2
Please enter StudyInstanceUID:
+ echo 'Exams are in!'
Exams are in!
+ echo 'What is the name of the owner: '
What is the name of the owner:
+ read
sftpuser
+ zipForOwner
+ arg1=
+ for i in '"${studyinstanceuids[#]}"'
+ zip -r /home/support/export/1.3.46.670589.16.11.8.34254330145.20140603.134057.0/20140620_1.3.46.670589.16.11.8.34254330145.20140603.134057.0.zip .
adding: .studiesToExportSend.txt.swp^C
zip error: Interrupted (aborting)
+ sudo chown : /home/support/export/1.3.46.670589.16.11.8.34254330145.20140603.134057.0/1.3.46.670589.16.11.8.34254330145.20140603.134057.0.zip
[sudo] password for support:
This line is your problem:
zip -r ~/export/"${studyinstanceuids[#]}"/20140620_"${studyinstanceuids[#]}".zip .
You're attempting to create a zip file called ~/export/"${studyinstanceuids[#]}"/20140620_"${studyinstanceuids[#]}".zip (good) with all of the contents in the current directory . (bad).
You need to change the . to be the folder you want zipped.

Resources