简体   繁体   中英

VSQL is generating output file using perl script but not in cronjob

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:

  1. Change to the directory before running your command
    */2 * * * * cd /some_directory_path && /usr/bin/perl /tmp/test.pl
  2. Include the full path in your Perl program
    -o /some_directory_path/dumpfile_". $timenow. ".txt

Update: 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 MAILTO parameter to the crontab. It will look like this:

MAILTO=someone@example.com
*/2 * * * * /usr/bin/perl /tmp/test.pl

Bear in mind that the server might not be set up to send external email, so you might need to use the local mail program 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 a systemd system, try journalctl _COMM=cron ).

The print() output is going somewhere. You need to track it down.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM