I want to redirect the error
python: can't open file '/usr/bin/file': [Errno 2] No such file or directory
I used this command
python /usr/bin/file 2> /dev/zero
but this is hiding all the output in my file , so I want to redirect only the not found error and nothing else .
Binary file is scripted by me through python giving this
Enter your password:
Welcome User :)
Checking your Secure Code now ...
Secure Code OK , Enjoy !!
What is the folder path ? ### This is hidden when used the code ###
You want /dev/null, not /dev/zero, which is a generator for scripts (you can read it for an endless stream of zero bytes if you ever need one).
The syntax you show does in fact redirect only standard error; if standard output is lost, it's because of something else.
Related
I want to schedule my Perl code to be run every day at a specific time. so I put the below code in bash file:
Automate.sh
#!/bin/sh
perl /tmp/Taps/perl.pl
The schedule has been specified in below path:
10 17 * * * sh /tmp/Taps/Automate.sh > /tmp/Taps/result.log
When the time arrived to 17:10 the .sh file hasn't been running. however, when I run ./Automate.sh (manually) it is running and I see the result. I don't know what is the problem.
Perl Code
#!/usr/bin/perl -w
use strict;
use warnings;
use Data::Dumper;
use XML::Dumper;
use TAP3::Tap3edit;
$Data::Dumper::Indent=1;
$Data::Dumper::Useqq=1;
my $dump = new XML::Dumper;
use File::Basename;
my $perl='';
my $xml='';
my $tap3 = TAP3::Tap3edit->new();
foreach my $file(glob '/tmp/Taps/X*')
{
$files= basename($file);
$tap3->decode($files) || die $tap3->error;
}
my $filename=$files.".xml\n";
$perl = $tap3->structure;
$dump->pl2xml($perl, $filename);
print "Done \n";
error:
No such file or directory for file X94 at /tmp/Taps/perl.pl line 22.
X94.xml
foreach my $file(glob 'Taps/X*') -- when you're running from cron, your current directory is /. You'll want to provide the full path to that Taps directory. Also specify the output directory for Out.xml
Cron uses a minimal environment and a short $PATH, which may not necessarily include the expected path to perl. Try specifying this path fully. Or source your shell settings before running the script.
There are a lot of things that can go wrong here. The most obvious and certain one is that if you use a glob to find the file in directory "Taps", then remove the directory from the file name by using basename, then Perl cannot find the file. Not quite sure what you are trying to achieve there. The file names from the glob will be for example Taps/Xfoo, a relative path to the working directory. If you try to access Xfoo from the working directory, that file will not be found (or the wrong file will be found).
This should also (probably) lead to a fatal error, which should be reported in your error log. (Assuming that the decode function returns a false value upon error, which is not certain.) If no errors are reported in your error log, that is a sign the program does not run at all. Or it could be that decode does not return false on missing file, and the file is considered to be empty.
I assume that when you test the program, you cd to /tmp and run it, or your "Taps" directory is in your home directory. So you are making assumptions about where your program looks for the files. You should be certain where it looks for files, probably by using only absolute paths.
Another simple error might be that crontab does not have permission to execute the file, or no read access to "Taps".
Edit:
Other complications in your code:
You include Data::Dumper, but never actually use that module.
$xml variable is not used.
$files variable not declared (this code would never run with use strict)
Your $files variable is outside your foreach loop, which means it will only run once. Since you use glob I assumed you were reading more than one file, in which case this solution will probably not do what you want. It is also possible that you are using a glob because the file name can change, e.g. X93, X94, etc. In that case you will read the last file name returned by the glob. But this looks like a weak link in your logic.
You add a newline \n to a file name, which is strange.
I try to redirect the result of RNAfold external program that take input files from ./Desktop/Data and want to save execution to the folder ./Desktop/Results/Rfam.
I tried to use the following logic: command < input >> output. But nothing happens except creating files that didn't exist before with a NULL length.
RNAfold < ./Desktop/Data/RF*.fa >> ./Desktop/Results/Rfam/res.txt
None of errors appeared. I work on MAC OS X and it is first time I used bash, I looked manual and saw examples that I used, but nothing happened. RNAfold didn't execute, but when I try RNAfold < RF*.fa >> res.txt
all is going well - obtained results for input files, but they appeared at the same folder.
Default behaviour of RNAfold is to take input from standard input (or the files following RNAfold command)and output to standard out. To specify the input file you can also use -i or --infile=. Similarly for output file -o or --outfile=.
RNAfold -i ~/Desktop/Data/RF*.fa -o ~/Desktop/Results/Rfam/res.txt
or try
RNAfold ~/Desktop/Data/RF*.fa -o ~/Desktop/Results/Rfam/res.txt
Reference
'echo 0 > Q:\FactoryRecovery\RECOVERY.INI:Done'
Can anyone please explain to me how this command works? I'm curious after reading this Superuser post: https://superuser.com/questions/384658/why-can-i-only-create-one-factory-backup-from-my-lenovo-thinkpad
It allows you to create more than one recovery disk.
Ok, heres a brief expanation:
Echo 0
Simply outputs 0 to the screen. Thats not to complicated. adding a >> and a file path after this will redirect the output to the end of the file. Adding a > will replace the contents of the file with what is being redirected.
Hence:
Echo 0 > Q:\FactoryRecovery\RECOVERY.INI
Will replace the contents of Recovary.INI with 0(while it used to be 1).
It prevents the file needed to create additional recovary disks from exiting, essentially allowin you to create more than one.
Mona.
I have a perl script that runs fine on Linux but fails on Windows at this point:
$freq{total} = 0;
dbmopen(%freq,$dictfile,0666) || die "Error: Cannot open dbmfile $dictfile";
$dictfile points to the proper location on the respective platforms. Changing the 0666 file permissions does not help. The file to open is a text file encoded in gb18030.
Is there a trick? Do I need to declare the encoding to open it on Window? Or possibly a different perl distro on Windows. I'm using Strawberry Perl.
Thanks.
Edit: Sorry, if I'm stating the obvious, but I just re-read the question. When you say
The file to open is a text file encoded in gb18030.
Do you mean a plain text file?
If so I think thats your problem. dbmopen is for indexed database file, ideally created by dbmopen in a previous run of you perl program. For plain text files you cannot bind them to hashes.
My previous resonse...
It works for me on Windows with Strawberry perl 5.12.1 running on Windows7x64. Which windows perl are you using? Make sure your installation has at least one of the DBM modules with it.
Some other points which might help:
You should include $! in your die statement, it will give you the error message for the failed open. So hopefully answer your question.
dbmopen will clear the contents of the %freq hash, so you will lose $freq{total} (because its 0 you may not notice). Usual pattern is: dbmopen, change some hash values, dbmclose
Edits:
$! is the variable which contains the error test of any failed "system" call. So you open line should be something like:
dbmopen(%freq,$dictfile,0666) || die "Error: Cannot open dbmfile $dictfile: $!";
To check for the standard DBM modules you can run the following from the command prompt
for %m in ( DB_File GDBM_File SDBM_File NDBM_File ODBM_File ) do #perl -M%m -e "print qq(%m: $%m::VERSION\n)"
For me that gives:
DB_File: 1.82
GDBM_File: 1.10
SDBM_File: 1.06
Can't locate NDBM_File.pm in #INC (#INC contains: C:/Nerd/StrawberryPerl/perl/site/lib C:/Nerd/StrawberryPerl/perl/vendor/lib C:/Nerd/StrawberryPerl/perl/lib .)
.
BEGIN failed--compilation aborted.
Can't locate ODBM_File.pm in #INC (#INC contains: C:/Nerd/StrawberryPerl/perl/site/lib C:/Nerd/StrawberryPerl/perl/vendor/lib C:/Nerd/StrawberryPerl/perl/lib .)
.
BEGIN failed--compilation aborted.
Which effectively meands I have DB_File, GDBM_File, and SDBM_File. But not NDBM_File or ODBM_File. Sorry I don't know how to find out which module dbmopen uses by default.
Personally I always use a specific module and then use the tie operator instead of dbmopen.
I am trying to run bro in my bash terminal. I have got a duplicate local.bro file which i renamed as localv2.bro, and put it in my working directory /home/bibin, so its not in default path. I am just trying to do a simple signature match, therefore i have created a signature.sig file in the directory. In my localv2.bro file i have tried using both ways:
#load-sigs ./signature
And
redef signature_files += "signature.sig
The signature.sig file has the signature my-first-sig example from bro.org site.
In the terminal when i try to execute this command:
bro -r traffic.pcap localv2.bro
I get an error message saying:
line 27: unrecognized character -
I have also tried doing it in a different route:
bro -r traffic.pcap -s signature.sig
This also gives me the same unrecognized character error.
Am i doing something wrong, please can you guide me to a solution ?