LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-01-2017, 10:50 AM   #1
chmod777
LQ Newbie
 
Registered: Sep 2017
Posts: 4

Rep: Reputation: Disabled
Problem with permissions when executing dmidecode in crond


Hi all, I am having a big problem and I have no idea what else can I do to solve it...

I created a NetCore application that reads and saves in a file some hardware information using dmidecode commands.

I deployed my application in a CentOS server, and assign it execution permissions by using the following command:

Code:
chmod 777 ApplicationFolder/AplicationName
Now, when I execute my application I get a log file with the information I asked. My problem is when I set my application to be executed with crond.

For that, I ran the command:

Code:
crontab -e
And inserted the line:

Code:
* * * * * /ApplicationFolder/ApplicationName
After some seconds my log file is created, when I check it out it contains the information I ask except the one retrieved by the execution of dmidecode commands.

I am assuming that its a permission problem because the application is working fine when executing via command line.

After some research, I have also discovered that dmidecode requires sudo privileges... but I executed crontab -e with the root account, so I should have the right privileges right?

These are some things I tried:

- Add the user account root to the crontab line (nothing happens, no file generated)
- Changed the permisions of the file dmidecode in /usr/sbin/ with the command chmod 777 but the same happens (no output from dmidecode commands)
- Changed the application internal commands to run sudo before the dmidecode commands (no output from dmidecode commands)
- Created the cron job by adding it to the file /etc/cron (nothing happens)

I don't know what else I can do. Anyone knows what I am doing wrong? Or what else can I attempt to do?
 
Old 09-01-2017, 11:39 AM   #2
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Are you running selinux? Maybe there is something there that is not allowing dmidecode to run from a cron job.

You can check selinux with
Code:
sestatus | grep -i mode
If the mode is set to enforcing you can change it with
Code:
setenforce 0
for testing and test your script again. to reactivate selinux after you are done run the command again with a 1 instead of the 0.

If it is set to disabled or permissive then selinux is not stopping you.

If permissions are set correctly and you know for sure that the cron job was setup under root I cannot think of any other reason for it not to work.

Last edited by lazydog; 09-01-2017 at 11:40 AM.
 
Old 09-01-2017, 01:37 PM   #3
chmod777
LQ Newbie
 
Registered: Sep 2017
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks for the reply.

I checked if selinux was running by using the command

Code:
sestatus
And the current mode was "enforcing", so I followed your instructions and changed the mode to "permissive", cleaned the log file and restarted crond, but I had the same results, no output from the dmidecode commands.

I checked the owner of the cron job by using the command ps -aux, and the user of the application executing was the root...

All the other commands called by my application work, only the dmidecode ones are failing only when executing via cron.

Any more ideas?
 
Old 09-01-2017, 01:43 PM   #4
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 759

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
Maybe: chmod +s
Maybe add id command in your script, to debug
strace -f -o myfile /usr/sbin/dmidecode

Welcome to LQ!!! Enjoy your study/learning

Last edited by !!!; 09-01-2017 at 01:52 PM.
 
Old 09-01-2017, 02:11 PM   #5
chmod777
LQ Newbie
 
Registered: Sep 2017
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by !!! View Post
Maybe: chmod +s
Maybe add id command in your script, to debug
strace -f -o myfile /usr/sbin/dmidecode

Welcome to LQ!!! Enjoy your study/learning
chmod +s in my executable or in dmidecode file?
 
Old 09-02-2017, 05:13 AM   #6
chmod777
LQ Newbie
 
Registered: Sep 2017
Posts: 4

Original Poster
Rep: Reputation: Disabled
After more research on the subject, I read somewhere that cron could be problematic when using relative paths.

So internally, in my NetCore application, I changed the commands to use absolute paths, so now instead of simply having dmidecode I have /usr/sbin/dmidecode, and that did the trick.

Not something related with permissions as I thought, but related with paths.

Thank you all for the sugestions.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem about using crond to execute rsync schwabeNiu Linux - Newbie 2 11-25-2010 08:27 AM
/sbin/service crond unable to start - gives permission error on /usr/sbin/crond mgervacio Linux - Newbie 6 07-16-2008 01:03 PM
crond problem branden_burger Linux - General 3 03-25-2005 05:03 PM
Memory Permissions For Executing Processes tim_l Linux - Software 3 02-24-2005 12:40 PM
problem running crond wakeupatul Linux - General 1 04-20-2004 01:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration