LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Ubuntu (https://www.linuxquestions.org/questions/ubuntu-63/)
-   -   cron.daily (https://www.linuxquestions.org/questions/ubuntu-63/cron-daily-472606/)

pigswillfly 08-10-2006 06:09 AM

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

blackhole54 08-10-2006 08:13 AM

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.

pigswillfly 08-10-2006 09:06 AM

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

binary_y2k2 08-10-2006 10:13 AM

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
....


pigswillfly 08-10-2006 10:24 AM

thanks for reply yes they are owned by mixmaster in /home/mixmaster already.

pigswillfly

binary_y2k2 08-10-2006 10:41 AM

If the script is run as root then the files created will be owned by root, so you'll need to change the ownership.

blackhole54 08-10-2006 07:13 PM

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.


All times are GMT -5. The time now is 08:17 AM.