LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Add user in Cron tab (https://www.linuxquestions.org/questions/linux-newbie-8/add-user-in-cron-tab-4175525783/)

phenriquerangel 11-18-2014 11:58 AM

Add user in Cron tab
 
Hy guys ,
I have a big difficult for add user in cron tab and execute a script with this user. ( any user)

Then , someone can help me?
How proceed I can solve this?

Thank in Advanced.

MensaWater 11-18-2014 12:06 PM

"crontab -e" if logged in as a given user will create/edit the crontab for that user. It is a vi session and you can add your entries there.

If you're the root user you can use above to modify root's crontab or "crontab -e -u <user>" to specify the user crontab you want to create/edit.

You can type "man 5 crontab" to find out the format of records to create.

Remember any script you run in crontab will need to be self contained with correct environment variables (especially PATH) as cron jobs do NOT login as the user but rather in a minimal environment. Most of the environment for users is created by logins and it won't be there in a cron job unless included in the script.

phenriquerangel 11-18-2014 01:59 PM

Quote:

Originally Posted by MensaWater (Post 5271471)
"crontab -e" if logged in as a given user will create/edit the crontab for that user. It is a vi session and you can add your entries there.

If you're the root user you can use above to modify root's crontab or "crontab -e -u <user>" to specify the user crontab you want to create/edit.

You can type "man 5 crontab" to find out the format of records to create.

Remember any script you run in crontab will need to be self contained with correct environment variables (especially PATH) as cron jobs do NOT login as the user but rather in a minimal environment. Most of the environment for users is created by logins and it won't be there in a cron job unless included in the script.


Then , I try for this steps ( just test).

1 - crontab -e -u orasid

2 - 24 16 * * * orasid mkdir /home/teste


And, this folder or file not criated in /home.

suicidaleggroll 11-18-2014 02:07 PM

Two things:
1) What is "orasid" doing in the command "orasid mkdir /home/teste"? Is that a program? What does it do?
2) Did you wait until 16:24 ?

szboardstretcher 11-18-2014 02:10 PM

Thats how you specify the username you want the command to run under. 'orasid' is an oracle os username iirc.

suicidaleggroll 11-18-2014 02:20 PM

But he did "crontab -u orasid", so he's already editing orasid's crontab. I just tried putting my own username in my own crontab, and it threw an error:
Code:

$ crontab -l
* * * * * user touch /home/user/cronfile

a minute later...
Code:

$ mail
N  3 (Cron Daemon)        Tue Nov 18 13:19  25/947  "Cron <user@computer>"
& t

yadda yadda yadda

/bin/sh: user: command not found


szboardstretcher 11-18-2014 02:43 PM

A few things to note
  • crontab -e will edit the current user's crontab. these crontabs have no 'username' field, as they run as the current user
  • the root crontab needs to use 'su user -c "command"' to specify another user, it has no 'username' field
  • the /etc/crontab and /etc/cron.d/* files support the 'username' field as I mentioned above

http://serverfault.com/questions/352...-specific-user

https://www.freebsd.org/doc/handbook...ning-cron.html

http://insanelabs.com/linux/linux-cr...ystem-reboots/

phenriquerangel 11-19-2014 08:31 AM

Quote:

Originally Posted by suicidaleggroll (Post 5271544)
Two things:
1) What is "orasid" doing in the command "orasid mkdir /home/teste"? Is that a program? What does it do?
2) Did you wait until 16:24 ?


Orasid is a user for oracle in system and yes. I wait for 16:30 , and nothing.

szboardstretcher 11-19-2014 09:42 AM

As i mentioned,.. if you are editing the user crontab,. which you are,. there is no 'username' field. So remove 'orasid' from the crontab, like this:


Code:

crontab -e -u orasid
24 16 * * * mkdir /home/test


phenriquerangel 11-19-2014 09:43 AM

Quote:

Originally Posted by szboardstretcher (Post 5271912)
As i mentioned,.. if you are editing the user crontab,. which you are,. there is no 'username' field. So remove 'orasid' from the crontab, like this:


Code:

crontab -e -u orasid
24 16 * * * mkdir /home/test


Uhn , ok . I'll try and reply.

phenriquerangel 11-19-2014 09:57 AM

Add user in Cron tab [RESOLVED]
 
Quote:

Originally Posted by phenriquerangel (Post 5271913)
Uhn , ok . I'll try and reply.


Thank you guys. I could create a script that works.



Steps

1 - Log for root , before log in user ( su - <user>) .

2 - Before that , create a crontab " crontab -e " . ( Logged in your user, not root)

3 - Create a script " 46 13 * * * touch /home/teste " ( minute hour mday month wday command ) , don't set user again.

OBS: Check the PERMINSSION in the folder.


All times are GMT -5. The time now is 09:34 PM.