LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 09: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, 09: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, 09: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, 10: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, 10:31 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
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, 10: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, 10:43 AM   #7
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian 11
Posts: 6,133

Rep: Reputation: 419Reputation: 419Reputation: 419Reputation: 419Reputation: 419
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, 11:17 AM   #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, 11:51 AM   #9
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian 11
Posts: 6,133

Rep: Reputation: 419Reputation: 419Reputation: 419Reputation: 419Reputation: 419
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, 12:09 PM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
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, 12:26 PM   #11
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian 11
Posts: 6,133

Rep: Reputation: 419Reputation: 419Reputation: 419Reputation: 419Reputation: 419
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, 02: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 02:45 PM.
 
Old 11-20-2009, 02: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, 03: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, 03: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 06:19 AM
find which program is calling cron every 10 minutes - using ubuntu intreoid getglenn Linux - Newbie 1 04-08-2009 03:53 AM
Cron every 5 minutes but not between midnight and 1 am xnomad Linux - Server 5 10-11-2007 12:17 PM
cron newusers command ? jchambers Programming 2 10-05-2007 02:38 AM
howto run a script from cron every 5 minutes except 11pm-8am ? cccc Programming 2 03-20-2005 03:52 AM

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

All times are GMT -5. The time now is 11:48 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