Can't exec “history”: No such file or director

2019-09-05 06:50发布

问题:

I'm trying to call "history" from a perl script but it keeps saying "Can't exec "history": No such file or directory at gatherinformation.pl line 7." Script:

#!/usr/bin/perl

use strict;
use warnings;

open(my $fich ,">>/home/osboxes/Desktop/ConteudosServer/Plano de contingencia/history_report.txt");
`history`;

I have tried only using history in the script but it keeps giving me the same error.

I'm have been messing around with the HISTFILESIZE and HISTFILE variables to output "%h/%d -- %H:%M:%S ". Heres is the line in the bashrc file:

export HISTTIMEFORMAT="%h/%d -- %H:%M:%S "

I have tried both of these answers: Can't exec No such file or directory

perl script error: Can't exec "module": No such file or directory at ./prog line 2

I don't think it's usefull to start another question just to ask this: is there a way to get the history directly from the file ./bash_history with date and time? I don't think it's usefull having to call shell commands to such a simple task.

回答1:

The problem is that history is a bash shell command, not a program in its own right

Even so, I am surprised you're getting that particular error message, as the backticks operator starts a new shell process and passes the string to it as a command, so it should work whether it's a shell process or not. I'm guessing that the default shell that Perl is using isn't bash. You can check for sure by running

perl -MConfig -E'say $Config{sh}'

But I wouldn't expect you to see any output anyway, as the new shell process will have no history, and so there should be no output from the command



回答2:

I think it's likely that perl is treating "history" as a stand-alone binary; the same reason why which history wouldn't produce anything - it's part of the shell built-in.



标签: perl shell