LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 11-18-2014, 12:58 PM   #1
phenriquerangel
LQ Newbie
 
Registered: Nov 2014
Posts: 7

Rep: Reputation: Disabled
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.
 
Old 11-18-2014, 01:06 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,577
Blog Entries: 14

Rep: Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969Reputation: 969
"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.
 
Old 11-18-2014, 02:59 PM   #3
phenriquerangel
LQ Newbie
 
Registered: Nov 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by MensaWater View Post
"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.
 
Old 11-18-2014, 03:07 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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 ?
 
Old 11-18-2014, 03:10 PM   #5
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,774
Blog Entries: 1

Rep: Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339
Thats how you specify the username you want the command to run under. 'orasid' is an oracle os username iirc.
 
Old 11-18-2014, 03:20 PM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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
 
Old 11-18-2014, 03:43 PM   #7
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,774
Blog Entries: 1

Rep: Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339
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/

Last edited by szboardstretcher; 11-18-2014 at 03:44 PM.
 
Old 11-19-2014, 09:31 AM   #8
phenriquerangel
LQ Newbie
 
Registered: Nov 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by suicidaleggroll View Post
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.
 
Old 11-19-2014, 10:42 AM   #9
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,774
Blog Entries: 1

Rep: Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339Reputation: 1339
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
 
Old 11-19-2014, 10:43 AM   #10
phenriquerangel
LQ Newbie
 
Registered: Nov 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by szboardstretcher View Post
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.
 
Old 11-19-2014, 10:57 AM   #11
phenriquerangel
LQ Newbie
 
Registered: Nov 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Add user in Cron tab [RESOLVED]

Quote:
Originally Posted by phenriquerangel View Post
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.
 
  


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
Cron Tab talat Solaris / OpenSolaris 1 06-07-2007 01:04 AM
cron tab user52 Linux - Newbie 3 11-29-2006 07:53 AM
help in cron tab framedrelay Programming 1 11-15-2006 08:49 AM
cron tab, what do you use it for? Fritz_Monroe Linux - Newbie 12 09-28-2006 03:54 PM
cron tab thefedexguy SUSE / openSUSE 4 07-06-2006 12:03 PM


All times are GMT -5. The time now is 02:41 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration