0

I have a problem regarding permissions in a CentOS server.

I created a NetCore application that reads some values from dmidecode. When I deployed the application in my CentOS server, I runned the following command:

chmod 777 ApplicationName

Then, I execute it, and eveything works fine.

My problem is when I try to set that application in crond, for that I do:

1) service crond stop

2) crontab -e

3) * * * * * cd /ApplicationFolder && ./ApplicationName

4) service crond start

My application is executed, but I can't get the dmidecode values I am trying to read, I am assuming that I am having a permission problem, because it works fine when executing as a console application.

I tried to set a user in the crond line by doing:

 * * * * * root cd /ApplicationFolder && ./ApplicationName

But nothing happens, the application isn't even started...

Does anyone knows what I am doing wrong?

EDIT

As proposed by the comments, I changed the crontab to:

 * * * * * /ApplicationFolder/ApplicationName

But the same is happening...

The reason why I think I am having a problem related with permissions its because if I run the program as an application values are logged into a text file, while when I execute the application using crond the same info is logged but the values are empty.

I also read that when reading Serial Numbers from dmidecode we would need root privileges, but my current account using crontab is already the root account.

5
  • Don't do cd but use absolute path to the program. In that case /ApplicationFolder/ApplicationName. Does your application writes those values to file or to stdout?
    – mrc02_kr
    Sep 1, 2017 at 13:03
  • 2
    There's absolutely no need to stop and restart the cron daemon when adding a cron job.
    – Kusalananda
    Sep 1, 2017 at 13:07
  • Are you sure that your user have write permission in directory in which you want to create your file? Edit your post as you trying new solutions. What is the location of file that should be created by your app?
    – mrc02_kr
    Sep 1, 2017 at 13:14
  • Ok, changed the line to * * * * * /ApplicationFolder/ApplicationName The values are logged to a text file. After the change I still can't get the values. The reason why I think its related with permissions its because if I execute the application with console everything works fine.
    – lulas
    Sep 1, 2017 at 13:14
  • I edited my post with some conclusions
    – lulas
    Sep 1, 2017 at 14:05

1 Answer 1

0

To anyone havin problem like this I managed to solve my problem by using absolute paths.

It seems that cron has some problems with relative paths...

Basically instead of having:

 dmidecode

I have:

 /usr/sbin/dmidecode

That did the trick for me.

1
  • 1
    Glad you got to the bottom of it! Another option would be to put PATH=$PATH:/usr/sbin at the top of the crontab.
    – Jeff Schaller
    Sep 3, 2017 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.