i have created the perl script in which i am connecting to vsql and running queries. when i run the script mannually, it is creating output files as expected. but when i set this script in crontab then output file is not generating. perl script is given below
#!/usr/bin/perl
$timenow = `date "+%H_%M"`;
chomp($timenow);
$cmd = "/opt/vertica/bin/vsql -d xxxx-U xxxxx -w xxxxx -F \$'--FSEP--' -At -o dumpfile_" . $timenow . ".txt -c \"SELECT CURRENT_TIMESTAMP(1) AS time;\"";
print "$cmd\n";
system($cmd);
and below is the contab entry
*/2 * * * * /usr/bin/perl /tmp/test.pl
can somebody please help what i am doing wrong ?
Your output is written to a file called
dumpfile_[timestamp].txt. But where is that file?Your command contains no directory path for that file. So it will be written to the current directory. The current directory for a cronjob is the home directory for the user that owns the cronjob. Have you tried looking there?
It's always better to be more specific about which directory you want the files written to. Two ways to do that are:
*/2 * * * * cd /some_directory_path && /usr/bin/perl /tmp/test.pl-o /some_directory_path/dumpfile_" . $timenow . ".txtUpdate: Ok, take two.
Who owns this cronjob? Any output from the cronjob will be emailed to the owner. And there's definitely output as you have a
print()statement. Any errors will be included in the same email. Do you get that email? What's in it?If you don't get the email, you can change the address that the email is sent to by adding a
MAILTOparameter to the crontab. It will look like this:Bear in mind that the server might not be set up to send external email, so you might need to use the local
mailprogram on the server.If you can't get the email to work out, you could look for cron errors in
/var/log/syslog(or, on asystemdsystem, tryjournalctl _COMM=cron).The
print()output is going somewhere. You need to track it down.