LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using Cron to make newusers every 10 minutes. (https://www.linuxquestions.org/questions/linux-newbie-8/using-cron-to-make-newusers-every-10-minutes-770446/)

Karas 11-20-2009 09:19 AM

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.

vishesh 11-20-2009 09:29 AM

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

Karas 11-20-2009 09:37 AM

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.

Karas 11-20-2009 10:13 AM

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.

catkin 11-20-2009 10:31 AM

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.

Karas 11-20-2009 10:34 AM

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.

tredegar 11-20-2009 10:43 AM

You'll also need to give the full path to the /usr/sbin/useradd command (and pretty much every other command too).

Karas 11-20-2009 11:17 AM

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

tredegar 11-20-2009 11:51 AM

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

catkin 11-20-2009 12:09 PM

Quote:

Originally Posted by tredegar (Post 3764124)
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 ...?

tredegar 11-20-2009 12:26 PM

Quote:

I think you meant in your script, not crontab ...?
I do. I had a "Senior Moment" (AKA, we hope not, "Alzheimer's hint") ;)

Karas 11-20-2009 02:20 PM

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

anomie 11-20-2009 02:44 PM

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


Karas 11-20-2009 03:03 PM

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?

anomie 11-20-2009 03:10 PM

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


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