0

I dont have a cron.allow and have a blank cron.deny file.

My crontab looks like below:

# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

# test entry
* * * * * echo `who am i` > /home/2125/RR_Dev_Code/ETL/crontab.test

But, this is not writing the user to the test file. The file gets created which means cron gets fired for my user. When i execute a who am i from CLI, it returns a valid user.

Am i missing something here ?

ForeverLearner
  • 1,901
  • 2
  • 28
  • 51
  • Are you trying to get a list of logged-in users, or are you trying to get the name of the user who's running the cron job? If the latter, the command `whoami` might better serve your purposes. – Quietust Apr 06 '17 at 14:18
  • Actually I try to run psql command. But I continue to get an error:/home/2125/RR_Dev_Code/loader.sh: line 4: psql: command not found . Hence I am trying to see which user cron is picking up to execute the script – ForeverLearner Apr 06 '17 at 14:31
  • 1
    Cron jobs don't automatically get your user-specific environment variables - see http://stackoverflow.com/questions/2388087/how-to-get-cron-to-call-in-the-correct-paths for more information. – Quietust Apr 06 '17 at 14:37
  • I have imported all the user specific variables as below: export PATH=$PATH:/usr/local/greenplum-db/./bin:/usr/local/greenplum-db/./ext/python/bin:/home/gpadmin/anaconda3/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/home/gpadmin/bin But I get the error: psql: error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory – ForeverLearner Apr 06 '17 at 16:23
  • The original problem is in this SO link: http://stackoverflow.com/questions/43260711/psql-error-while-loading-shared-libraries-libpq-so-5-cannot-open-shared-objec – ForeverLearner Apr 06 '17 at 16:32

1 Answers1

0

Here is my suggestion

Add proper logging,

* * * * * echo `who am i` 1> /home/2125/RR_Dev_Code/ETL/crontab.test.out 2>/home/2125/RR_Dev_Code/ETL/crontab.test.err

Then see the content of the files. It will tell you the precise problem. (And BTW, it should be whoami not who am i)

NinjaGaiden
  • 3,046
  • 6
  • 28
  • 49
  • The command could be simplified by removing the echo command and the backquotes. – pcjr Apr 06 '17 at 16:06
  • As per SO rules: I am able to see the user. The original problem is not being able to run psql utility for the user. I have accepted the answer as I never asked that in this question. – ForeverLearner Apr 06 '17 at 16:30