I need a shell script writing - any takers?

Soldato
Joined
12 Jan 2004
Posts
6,824
Location
Londinium
Hi guys,

I need a shell script writing that I can set up as a cron job. I thought I could do this myself, but after looking at a few tutorials I realised it just wouldnt happen any time soon!

So, I want the script to copy an image file, named in the format:

Code:
daily_usage_xy.png
where: x = full year   y = day of month
e.g. daily_usage_200602.png

from the directory:

Code:
/tmp/webalizer/

to the directory:

Code:
/public_html/admin/webstats/

but renamed to:

Code:
daily_usage.png

so it overwrites the old one.

The idea being that today's daily usage webalizer image is copied (each day - via cron) to a directory where I can access it with an html file.

If someone could do this for me that would be grrrrrrrreat! :)
 
Visage said:
As its friday and i need to eat up the time until hometime....

Code:
#!/bin/sh

YEAR=$(date +%Y)
MONTH=$(date +%m)

SOURCE_DIR="/tmp/webalizer/"
DEST_DIR="/public_html/admin/webstats/"

SOURCE_FILE=${SOURCE_DIR}daily_usage_${YEAR}_${MONTH}.png
DEST_FILE=${DEST_DIR}daily_usage.png

cp -f $SOURCE_FILE $DEST_FILE

Might need some tweaking/some defensive code for if the files dont exist, etc but you get the idea....

EDIT: obviouslyt there shouldnt be a gap in MONTH.....

Thanks visage but I get this error:

Code:
/bin/sh: /home/olympus/public_html/scripts/webstats.scr: /bin/sh
: bad interpreter: No such file or directory

I have ammended your code to this:

Code:
#!/bin/sh

YEAR=$(date +%Y)
MONTH=$(date +%m)

SOURCE_DIR="/home/olympus/tmp/webalizer/"
DEST_DIR="/home/olympus/public_html/admin/webstats/"

SOURCE_FILE=${SOURCE_DIR}daily_usage_${YEAR}${MONTH}.png
DEST_FILE=${DEST_DIR}daily_usage.png

cp -f $SOURCE_FILE $DEST_FILE

Any thoughts?
 
Back
Top Bottom