LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 05-16-2004, 08:43 PM   #1
goldstonrumpke
LQ Newbie
 
Registered: May 2004
Posts: 3

Rep: Reputation: 0
Help with Script and Cron


I can run the script manually via the shell but I want to set up my Crontab to do this for me. I am tired of these tedious tasks and that is what Cron is for right? Please if anyone can help I would be grateful

Thanks in advance ...

/* this is my script */

#!/bin/bash
cp -u /home/ccs/* /var/ftp/ccs
exit

/* this is how I tried to update with crontab */

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

30 * * * * /bin/bash /root/scripts/update.sh
00 * * * * /bin/bash /root/scripts/update.sh
 
Old 05-16-2004, 09:00 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
I wonder if you would have better luck making it executable. Something like this.....

Make a file called /home/test
#!/bin/bash
cp -u /home/ccs/* /var/ftp/ccs
exit

Run these commands:
chmod +x /home/test
export EDITOR=vi
crontab /etc/crontab
crontab -e

Add a line to your personal crontab.....
30 * * * * /home/test

Save the changes with the command: :wq!

Don't forget to start the crond service.
 
Old 05-17-2004, 02:04 AM   #3
pcardout
Member
 
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("lenny", "squeeze"), Linux Mint, XUbuntu
Posts: 218

Rep: Reputation: 24
Help with Script and Cron

Oooh ooh I know -- cause I had this EXACT problem.

You have to say /bin/cp ... plain cp doesn't work. That's probably ALL
that's wrong. Here's some other info you didn't ask for.

Setup a cron job
crontab -urichard -l (to list) and crontab -urichard -e (to edit)
If crontab doesn't allow you to do this, put the name richard in
the file. /etc/cron.allow (create the file if you need to). You do not
need to stop and start cron ... at least not when using crontab, possibly
when creating the cron.allow file.


Here is a working crontab file
# Beginning of crontab file
SHELL=/bin/bash
# Select a shell to use
* * * * * /bin/echo "One minute has elapsed">>/home/richard/rscron.log
# Output this message every minute. Note that have to use a path
# explicitly for echo as the usual path is not what cron uses. Without the
# /bin, this script produces no output.
 
Old 05-18-2004, 03:14 AM   #4
aeichner
LQ Newbie
 
Registered: Apr 2004
Location: Zittau, Germany
Distribution: Debian GNU/Linux (testing-release)
Posts: 9

Rep: Reputation: 0
Hmmm. If you _really_ want to put your Script in the global crontab, don't forget to set the username. Cron normally runs as root and also all the scripts it will run for you - this is bad security. So set the username, either "root" or better a non-privilleged user.

But I suggest to use the way described above. If it's normally the job of your user, then use a personal crontab to do the job.
 
Old 05-19-2004, 09:41 PM   #5
goldstonrumpke
LQ Newbie
 
Registered: May 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you for all of the help ...
I tried this one ... crontab -uroot-l (to list) and crontab -uroot-e (to edit) , and the shell said "no crontab for user root" How would I make a crontab for the specific user? What is a global crontab and why is it bad? This is the one I am using right? Is it the file in the root file system? How could I limit to a specific user? I am so confused.

I will keep trying
Thanks in Advance .
 
Old 05-19-2004, 09:43 PM   #6
goldstonrumpke
LQ Newbie
 
Registered: May 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Yep, I also CHMODed the directory

I forgot to write that I also CHMODed the directory as indicated.
 
Old 05-19-2004, 10:58 PM   #7
pcardout
Member
 
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("lenny", "squeeze"), Linux Mint, XUbuntu
Posts: 218

Rep: Reputation: 24
I just tried the following on my system and got a result similar to yours. Here it is:

"garage:/etc# crontab -uroot -l
You (root) are not allowed to use this program (crontab)
See crontab(1) for more information".

Here's what I think is happening. Linux is trying to protect you from running crontab as root. It really wants you to run it as some other user. Here is how you do that:

I'll assume you have a user on your system called adam.

Then you edit /etc/cron.allow (creating it if it doesn't exist) and add
a line that simply says "adam". (No quotes). My /etc/cron.allow consists of a single line, "richard". That's it.

Then you can crontab -uadam -e. You will notice that you are dropped into an empty file, you aren't messing with that crontab "minute", "hour" day file. That's the one that aeichner called "global". Go look at the example crontab file I showed in my last post. I specifically had it write a message once a minute so I wouldn't have to wait too long to see if it was working! Once you've got that, you should be able to do whatever you want.
 
Old 05-30-2004, 09:34 PM   #8
kenji1903
Member
 
Registered: Apr 2004
Location: M'sia, Aus, Chn
Distribution: Redhat Linux 8 & 9, Fedora Core 2, XP
Posts: 301

Rep: Reputation: 30
G'day!

Interesting post!
Will's my username...
I had tried crontab -uwill -e and inserted your line in it, works like a charm

Then I thought, hey, why not try rebooting it and see whether cron will run...
I inserted:
00 10 * * * /sbin/reboot
# 10am is just my local time

Then i got this message: You have a new mail in /var/spool/mail/will

When I check the file, i got this: reboot: must be superuser

If i want to reboot my server daily at 2am in the morning, how do i set cron to do that?

Cheers!
 
Old 05-30-2004, 11:10 PM   #9
fortezza
Member
 
Registered: Mar 2003
Location: Colorado
Distribution: Fedora Core 4
Posts: 297

Rep: Reputation: 30
Reoobt permissions

do an "ls -l `which reboot'" ( without the double quotes, keep the backticks ) and make sure you have permission to run the reboot command. if you don't, then what I would do is use chmod to let you do that, and then try it from the command line to make sure it works. Another option for reboot is "shutdown -r now", which also requires that you have permission to run it.
 
Old 05-30-2004, 11:21 PM   #10
kenji1903
Member
 
Registered: Apr 2004
Location: M'sia, Aus, Chn
Distribution: Redhat Linux 8 & 9, Fedora Core 2, XP
Posts: 301

Rep: Reputation: 30
Well, its owned by root alright...

Instead of changing the ownership of the file, is it possible to add my user "will" into the group root? is it recommended to do so?



do an "ls -l `which reboot'" ( without the double quotes, keep the backticks ) and make sure you have permission to run the reboot command. if you don't, then what I would do is use chmod to let you do that, and then try it from the command line to make sure it works. Another option for reboot is "shutdown -r now", which also requires that you have permission to run it.
 
Old 05-30-2004, 11:51 PM   #11
kenji1903
Member
 
Registered: Apr 2004
Location: M'sia, Aus, Chn
Distribution: Redhat Linux 8 & 9, Fedora Core 2, XP
Posts: 301

Rep: Reputation: 30
hmm... whats the difference between:
/usr/bin/reboot
/sbin/reboot
?
Which one usually gets executed?
 
  


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
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
can't get cron to run my script. dr_zayus69 Linux - Software 6 04-12-2005 06:34 PM
PPPD Script problem when cron-scheduling the script andresurzagasti Linux - Networking 0 11-24-2004 02:54 PM
Cron script help mpls mikeg Linux - Software 2 09-24-2004 09:28 AM
cron problem with script lifetaster Linux - Newbie 3 02-24-2004 12:26 AM


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