LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training 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-20-2009, 10:19 AM   #1
Karas
Member
 
Registered: Oct 2009
Distribution: Slackware 13.0
Posts: 49

Rep: Reputation: 15
Using Cron to make newusers every 10 minutes.


Hi, I am trying to make the crond run a script which is located in my home directory every ten minutes. The script as guessed runs the newusers command.

--crontab file for root--
#Create all user accounts in newusers.txt file
*/10 * * * * /home/karas/userlist 1> /dev/null

--userlist file located in my home directory--
#!/bin/bash
newusers public_html/newusers.txt
echo -n > public_html/newusers.txt

Then the new newusers.txt file is in the public_html folder and contains the users to be created. The file is in the correct format as I was able to do the newusers command manually as root and it created the users.

But I am stumped as to why the crond does not work. I've had the cron send me emails every 10 minutes just to see that it is working.

So I am pretty lost.

Thanks in advance.
 
Old 11-20-2009, 10:29 AM   #2
vishesh
Member
 
Registered: Feb 2008
Distribution: Fedora,RHEL,Ubuntu
Posts: 661

Rep: Reputation: 66
Check the execute permission on your script file.
Try to just specify 777 on script file once just to check that there is no permission related issue.

Thanks
 
Old 11-20-2009, 10:37 AM   #3
Karas
Member
 
Registered: Oct 2009
Distribution: Slackware 13.0
Posts: 49

Original Poster
Rep: Reputation: 15
No, that doesn't appear to have made any difference. i've made both the userlist script and newusers.txt have permissions of 777, and nothings changed.
 
Old 11-20-2009, 11:13 AM   #4
Karas
Member
 
Registered: Oct 2009
Distribution: Slackware 13.0
Posts: 49

Original Poster
Rep: Reputation: 15
UPDATE:

OK the cron appears to be executing the userlist file....But it's not making the users in the list, it's just deleting everything in the file.
 
Old 11-20-2009, 11:31 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Try giving the full path of the newusers command or setting $PATH in your script. cron runs things in a process environment with a limited $PATH as you can demonstrate by modifying your script to echo $PATH to a file.
 
Old 11-20-2009, 11:34 AM   #6
Karas
Member
 
Registered: Oct 2009
Distribution: Slackware 13.0
Posts: 49

Original Poster
Rep: Reputation: 15
In the cron i've given a full path of /home/karas/userlist

And in the userlist file i've given the full path of /home/karas/public_html/newusers.txt

Still no luck. Just deletes the entries without creating a user account.
 
Old 11-20-2009, 11:43 AM   #7
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,087

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
You'll also need to give the full path to the /usr/sbin/useradd command (and pretty much every other command too).
 
Old 11-20-2009, 12:17 PM   #8
Karas
Member
 
Registered: Oct 2009
Distribution: Slackware 13.0
Posts: 49

Original Poster
Rep: Reputation: 15
But I am using newusers? That just takes the contents of a file in the correct format and uses the data to make a new user account? No? :-S
 
Old 11-20-2009, 12:51 PM   #9
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,087

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
Quote:
But I am using newusers?
I have never used that command, but I see I have it here:

/usr/sbin/newusers

So, make sure you reference it with the /full/path_to/newusers in your crontab
 
Old 11-20-2009, 01:09 PM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by tredegar View Post
I have never used that command, but I see I have it here:

/usr/sbin/newusers

So, make sure you reference it with the /full/path_to/newusers in your crontab
I think you meant in your script, not crontab ...?
 
Old 11-20-2009, 01:26 PM   #11
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,087

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
Quote:
I think you meant in your script, not crontab ...?
I do. I had a "Senior Moment" (AKA, we hope not, "Alzheimer's hint")
 
Old 11-20-2009, 03:20 PM   #12
Karas
Member
 
Registered: Oct 2009
Distribution: Slackware 13.0
Posts: 49

Original Poster
Rep: Reputation: 15
Done that, and got nothing :| Just an empty newusers.txt file.

UPDATE: I got it to do the newusers command and make a new acocunt, however that was only after I commented out the echo -n command.... What is going on :s

Last edited by Karas; 11-20-2009 at 03:45 PM.
 
Old 11-20-2009, 03:44 PM   #13
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Change your script to:
Code:
#!/bin/bash

PATH=/bin:/usr/bin:/usr/sbin

_users=/full/path/to/public_html/newusers.txt

newusers ${_users}

if [ ${?} -ne 0 ] ; then
  echo "${0} error: check root's mail for clues" > ${_users}
  exit 1
fi

echo -n > ${_users}

exit 0
 
Old 11-20-2009, 04:03 PM   #14
Karas
Member
 
Registered: Oct 2009
Distribution: Slackware 13.0
Posts: 49

Original Poster
Rep: Reputation: 15
After doing that in the mail for root is the following:

Quote:
/home/karas/userlist: line 21: syntax error: unexpected end of file
What the foo?
 
Old 11-20-2009, 04:10 PM   #15
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Did you copy and paste the script exactly? There are only 16 lines there...
 
  


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
How to create user account with a 'newusers' run from a cron job? tifoso Linux - General 3 11-05-2009 07:19 AM
find which program is calling cron every 10 minutes - using ubuntu intreoid getglenn Linux - Newbie 1 04-08-2009 04:53 AM
Cron every 5 minutes but not between midnight and 1 am xnomad Linux - Server 5 10-11-2007 01:17 PM
cron newusers command ? jchambers Programming 2 10-05-2007 03:38 AM
howto run a script from cron every 5 minutes except 11pm-8am ? cccc Programming 2 03-20-2005 04:52 AM

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

All times are GMT -5. The time now is 03:24 PM.

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