LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 08-10-2006, 06:09 AM   #1
pigswillfly
LQ Newbie
 
Registered: Apr 2006
Posts: 7

Rep: Reputation: 0
cron.daily


I have placed this script called update in my /etc/cron.daily and made sure it is with chmod 755.
does it look ok/
i have to insert the urls i know about this


lex1

#!/bin/bash
cd /home/mixmaster/Mix
# Get Stats
wget -O - http://www.
mlist.tmp

if [ -s mlist.tmp ]
then
cp mlist.tmp mlist.txt
fi

# Get Keys
wget -O - http://www.
pubring.tmp

if [ -s pubring.tmp ]
then cp pubring.tmp pubring.mix
fi


--------------------------------------------------------------
here is etc/crontab



# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file.
# This file also has a username field, that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user command
17 * * * * root run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || run-parts --report /etc/cron.daily
47 6 * * 7 root test -x /usr/sbin/anacron || run-parts --report /etc/cron.weekly
52 6 1 * * root test -x /usr/sbin/anacron || run-parts --report /etc/cron.monthly
 
Old 08-10-2006, 08:13 AM   #2
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
If you are redirecting output from your wgets to the files on the next line (as opposed to the way it appears in your post), it looks fine to me. But generally one tests scripts or programs before deploying them.

To do this, log in as root, set the SHELL and PATH variables to match what is shown in your /etc/crontab file and run the script to see if it produces the anticipated results (assuming the pages you are wgeting aren't time critical).

And to be honest, I usually don't bother setting the environmental variables like a just told you to, but when I don't match the same environment it will use with cron, I run a small risk of the test producing results that will differ from what it produces as a cron job. It's just a matter of what risks you are willing to take.
 
Old 08-10-2006, 09:06 AM   #3
pigswillfly
LQ Newbie
 
Registered: Apr 2006
Posts: 7

Original Poster
Rep: Reputation: 0
script

thanks for your post

>If you are redirecting output from your wgets to the files on the next line (as opposed to the >way it appears in your post)
>

i am not sure if i am redirecting the wgets to the files on the next line ?
what should appear at the end of the url so the wgets are ouputting to the file on the next line?

pigswillfly

Last edited by pigswillfly; 08-10-2006 at 09:07 AM.
 
Old 08-10-2006, 10:13 AM   #4
binary_y2k2
Member
 
Registered: Jul 2005
Location: England, UK
Distribution: Ubuntu 8.04 Server, Kubuntu 12.04
Posts: 698
Blog Entries: 1

Rep: Reputation: 31
it should be something like
Code:
wget -O - http://www. > mlist.tmp
the ">" sign meens to redirect the output of the command on the left of it to the file on the right.
You may also want to change the owner of the files you are creating so they aren't owned by root.
so you could use
Code:
#!/bin/bash
cd /home/mixmaster/Mix
# Get Stats
wget -O - http://www. > mlist.tmp

if [ -s mlist.tmp ]
then
cp mlist.tmp mlist.txt
chown mixmaster:mixmaster mlist.txt
else
rm mlist.tmp
fi
....
 
Old 08-10-2006, 10:24 AM   #5
pigswillfly
LQ Newbie
 
Registered: Apr 2006
Posts: 7

Original Poster
Rep: Reputation: 0
thanks for reply yes they are owned by mixmaster in /home/mixmaster already.

pigswillfly
 
Old 08-10-2006, 10:41 AM   #6
binary_y2k2
Member
 
Registered: Jul 2005
Location: England, UK
Distribution: Ubuntu 8.04 Server, Kubuntu 12.04
Posts: 698
Blog Entries: 1

Rep: Reputation: 31
If the script is run as root then the files created will be owned by root, so you'll need to change the ownership.
 
Old 08-10-2006, 07:13 PM   #7
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
Actually, since there is no need to be running this script as root if user mixmaster has permission to write to /home/mixmaster/Mix, and since this script does internet access, it would be more secure to run the main script as mixmaster rather than root (in case there is an exploitable bug in wget).

This can be done in three ways. One is to remove the script from cron.daily and create a new /etc/crontab entry with the user field set to mixmaster. Another is to remove the script from cron.daily and use mixmaster's own crontab (using the program crontab -- see man pages). Or you can leave the script in cron.daily and change the user by having the script call itself, something like:

Code:
#!/bin/sh

if [ $(id -u) -eq 0  ]; then
   su -c "$0" mixmaster
else

{  Insert main body of script here  }

fi
(While programs have setuid() available to directly change the user, I am not aware of any such direct capability in bash, which is why I have the script call itself.)

In all of these cases, since the main body of the script is executed as mixmaster, there is no need to change ownership of the files.
 
  


Reply



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 Job Daily petenyce Linux - Newbie 17 01-04-2006 11:13 AM
crontab vs cron.daily ? SheldonPlankton Linux - Newbie 1 07-16-2004 12:10 PM
cron.daily error gjmwalsh Mandriva 2 10-29-2003 02:12 PM
cron.daily MrJoshua Linux - General 2 03-19-2003 12:09 PM
dual entries in cron log for cron.daily cpharvey Linux - General 3 02-27-2003 02:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

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