Note that there are some explanatory texts on larger screens.

plurals
  1. POUser id in perl cron job
    text
    copied!<p>I have a Perl script which is running as cron job (every minute). Now, I do certain computation and execution in my file. Whenever the job is running, it does not get access to some folders in the file system. </p> <p>For example, I have folder named <code>/opt/tinyos-2.x/apps/</code>. I have kept this folder public (with 777 permission). I change directory to this folder in my Perl script and try to execute files there. But it does not run, instead I get error saying that:</p> <pre><code>make: *** No rule to make target `telosb'. Stop. </code></pre> <p>I can replicate this error whenever I go to that folder and execute files as sudo. </p> <ol> <li><p>So, I am assuming that my cron somehow becomes "root" (I have my cron under the same user as above folder owner). So what should I do with this kind of problem? </p></li> <li><p>I feel that if I can get user who is currently running in that Perl script, I might find it's user id . Could anyone tell me how can I get the user id in my Perl script? After checking at various places, I found this solution to know user id - <code>print $ENV{"LOGNAME"}</code>. Is this the correct way to know the user in Perl script run by cron job ?</p></li> </ol> <p>Here is what I have: I have a user id "abc". </p> <pre><code>abc@mymachine:crontab -e # Edit this file to introduce tasks to be run by cron. # # Each task to run has to be defined through a single line # indicating with different fields when the task will be run # and what command to run for the task # # To define the time you can provide concrete values for # minute (m), hour (h), day of month (dom), month (mon), # and day of week (dow) or use '*' in these fields (for 'any').# # Notice that tasks will be started based on the cron's system # daemon's notion of time and timezones. # # Output of the crontab jobs (including errors) is sent through # email to the user the crontab file belongs to (unless redirected). # # For example, you can run a backup of all your user accounts # at 5 a.m every week with: # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ # # For more information see the manual pages of crontab(5) and cron(8) # # m h dom mon dow command * * * * * /usr/bin/perl /var/www/web/myfolder/LoadPrograms.pl &gt;&gt; /var/www/web/log.txt </code></pre> <p>LoadPrograms.pl</p> <pre><code>#!/usr/bin/perl use DBI; use strict; use Thread; use File::Path; $nullPath = "/opt/tinyos-2.x/apps/Null"; chdir($nullPath) or die "cant chnge directory to null directory\n"; my $nullProgramCommand = "make telosb install.1 bsl,/dev/ttyUSB0"; my $output.=`$nullProgramCommand`; print $output; </code></pre> <p>When my job is running in cron, I don't see any output or anything happening. I get mail at user id location /var/mail/abc :</p> <pre><code>Content-Type: text/plain; charset=ANSI_X3.4-1968 X-Cron-Env: &lt;SHELL=/bin/sh&gt; X-Cron-Env: &lt;HOME=/home/abc&gt; X-Cron-Env: &lt;PATH=/usr/bin:/bin&gt; X-Cron-Env: &lt;LOGNAME=abc&gt; make: *** No rule to make target `telosb'. Stop. </code></pre> <p>This means that It is not running my code at the location I mentioned: /opt/tinyos-2.x/apps/Null. </p> <p>Can anybody help me with this ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload