perl - 我想用 crontab (Centos 7) 自动运行 1 个文件 Demfile.pl。但是 /var/spool/mail/root 发送邮件到日志如下
问题描述
我想Demfile2.pl
用crontab
(Centos 7)自动运行 1 个文件。但是/var/spool/mail/root
发送邮件到日志如下:
DBD::SQLite::db do failed: no such table: HISTORY1 at /root/perl/test/Demfile2.pl line 31.
DBD::SQLite::db do failed: no such table: HISTORY1 at /root/perl/test/Demfile2.pl line 31.
我不知道为什么:((这是我的代码:
use DBI;
my $driver = "SQLite";
my $database = "test.db";
my $dsn = "DBI:$driver:dbname=$database";
my $userid = "";
my $password = "";
my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) or die $DBI::errstr;
print "Opened database successfully\n";
$dir = "/root/perl/test*";
my @file = glob($dir);
@files = glob("test");
$temp = 0;
$size = @file;
$tempsize = 0;
for (my $i = 0; $i < $size; $i++){
print @file[$i];
$temp++;
my $filesize = -s "@file[$i]";
print "$filesize\n";
$tempsize += $filesize;
my $now = date "+%Y-%m-%d//%H-%M-%S" | tr -d "\n";
my $stmt = qq(INSERT INTO HISTORY1 (ID, TIME_NOW, TEN_FILE, SO_FILE, SIZE, HETHONG)VALUES ($i, '$now', '$file', '$tempsize', '$tempsize', 'A'));
my $rv = $dbh->do($stmt) or die $DBI::errstr;
print "Records created successfully\n";
}
$dbh->disconnect();
print"\n";
print "so file $temp\n";
print "total size $tempsize\n";
解决方案
我不知道为什么 :((
但是错误信息很清楚。
没有这样的表:HISTORY1
所以在我看来,您的数据库文件 ( test.db
) 不包含您认为的数据库模式。您可以使用 SQLite 命令行工具来测试这个理论,sqlite3
. 尝试运行以下命令:
$ sqlite3 test.db
sqlite> .tables
这将为您提供test.db
文件中表的列表。希望您会在此处看到“HISTORY1”。
另一件事要检查。您是否从正确的目录运行它?您的代码似乎假定它是从包含该test.db
文件的目录中运行的。如果您从任何其他目录运行代码,那么我认为它将创建一个新的、空的数据库文件,显然,它不会包含您的表。
推荐阅读
- django - Django:将带注释和聚合的查询集序列化为 GeoJSON
- android - 在应用程序审查(FakeReviewManager)对话框中未显示在 android
- c++ - 在 Linux 的 Windows 子系统中的 Ubuntu 20 下编译时未定义的引用
- python - 调用 sklearn 缩放器时如何抑制详细输出?
- netlogo - 如何在不透露或发送实际代码的情况下与合作者共享我的 netlogo 模型?
- ethereum - ethereum 文件夹中没有 geth.ipc
- postgresql - 使用 r2dbc-postgresql 的事务
- java - 从 Jshell 运行 echo 示例
- r - 使用变音符号查看(kwic)
- java - 使用 IPv6 的 Java 套接字编程