The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
retrieved multiple lines on multiple places in a file dala Shell Programming and Scripting 8 03-14-2008 12:28 PM
Find, Append, Move & Rename Multiple Files Trapper Shell Programming and Scripting 5 08-30-2007 04:39 AM
move file ust Shell Programming and Scripting 1 08-04-2005 12:01 AM
move from one IP to another >ystrdays file maverick Shell Programming and Scripting 14 11-12-2003 03:44 AM
help move file hassan2 UNIX for Advanced & Expert Users 1 04-23-2002 11:31 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 02-20-2008
Registered User
 

Join Date: Feb 2008
Posts: 2
Multiple stage file move?

Greetings all.

I need is a script that will move a file from one known dir to another, then grab another file from a different dir to replace it, and have absolutely zero clue how to do this.
Here's what I am trying to do:
A web client wants his site header image to change based on US holidays.
So, a script would grab the default header jpg, move it to a different dir somewhere on the site, then grab a header that has, say, a Christmas theme, and move that into the dir where the default one was. Make sense?

I could then make a cron job that exe's the script based on known holiday dates.
Reply With Quote
Forum Sponsor
  #2  
Old 02-20-2008
Smiling Dragon's Avatar
Disorganised User
 
Join Date: Nov 2007
Location: New Zealand
Posts: 734
Post

Your solution (you'll probably need to wrap some additional logic and error handling etc round this):
Code:
#!/bin/sh
THEMEDDIR=/export/home/httpd/themes
HTMLDIR=/export/home/httpd/htdocs
FILE=header.jpg
THEME=xmas

if [ -r $HTMLDIR/$FILE ]
then
  cp -p $HTMLDIR/$FILE $THEMEDIR/${FILE}.default
  cp $THEMEDIR/${FILE}.${THEME} $HTMLDIR/$FILE
fi
An alternative approach - use symbolic links:
Code:
#!/bin/sh
HTMLDIR=/export/home/httpd/htdocs
FILE=header.jpg
if [ -r ${HTMLDIR}/${FILE}.$1 ]
then
  rm -f ${HTMLDIR}/${FILE}
  ln -s ${HTMLDIR}/${FILE}.$1 ${HTMLDIR}/${FILE}
else
  echo "$1 version of $FILE not found!"
  exit 1
fi
Usage: scriptname.sh <theme>
Where theme is something like 'xmas' or 'default' etc.

Them just have a copy of the header.jpg file for each theme (eg header.jpg.xmas), including the plain one called header.jpg.default.
Run this script to switch to whatever one you need.
Reply With Quote
  #3  
Old 02-21-2008
Registered User
 

Join Date: Feb 2008
Posts: 2
Awesome, thanks a lot. I'll give it a try.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0