Re: Automate a command


Subject: Re: Automate a command
From: Andy Firman (lug@firman.us)
Date: Wed Jun 11 2003 - 15:14:55 AKDT


On Wed, Jun 11, 2003 at 12:23:43PM -0800, Greg Madden wrote:
>
> The following command + options creates a Debian mirror. I run it
> manually when I want to update my mirror. What I would like to do is
> make it so it runs automatically a couple of times a week. I don't know
> aything about scripts or cron jobs so a sequence of events and the
> terminology involved would help point me to research the correct docs.
>
> # 'debmirror -a i386,powerpc -h ftp-mirror.internap.com -r /pub/debian
> --ignore=non-US/ -d woody -d testing -d unstable /mnt/pub/mirror/debian
> -p --getcontents'
>
> This is all one line separated by blank spaces.

Cron is easy to learn.
First simply type crontab -l which will list your
cron jobs. (probably none)

If you want to make a cron job then type crontab -e
and then you can enter in your information.
I use nano as my editor of choice for doing this
and I think it is the default in Debian...not sure.

I enter the following into my crontab to show the proper entries.
This is so very helpful and I recommend everyone use this:

------------------------------------------------------------------
#minute (0-59)
#| hour (0-23)
#| | day of the month (1-31)
#| | | month of the year (1-12)
#| | | | day of the week (0-6 with 0=Sunday)
#| | | | |

0 10 * * 5 echo put tape on server | mail andy@firman.us
0 10 * * 1,4 echo update webpage | mail andy@firman.us
------------------------------------------------------------------

This example shows 2 simple cron jobs that email me reminders.
The first happens every Friday at 10am.
The second happens every Tues. and Thurs. at 10am.
You get the idea. Very useful for emailing reminders
to my clients to change tapes on tape drives for backup.
(they always used to forget....but no more)

Now you can either put the whole command in there
or create a script, make it executable, and then
for the command just type in something like
/home/greg/myscript
 
To make a script just do this:
touch myscript (this makes a blank file called myscript)
vi myscript (or nano myscript and this will open the file in an editor)
and add #!/bin/bash on the first line
and then add in your big long command.
Then you can add something like:
echo the debian mirror job is done | mail pabi@gci.net
which will email you when done.
Then you can put in exit 0 at the end but I don't
think that is necessary. If you look at all the startup
scripts in /etc/init.d you will see they have exit 0.

Make it executable by doing
chmod +x myscript

Check out man crontab for further clarification.

Thanks,

Andy Firman
Firman Consulting, LLC
Wasilla, Alaska
907-357-3699

---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.



This archive was generated by hypermail 2a23 : Wed Jun 11 2003 - 15:16:33 AKDT