Multiple stage file move?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Multiple stage file move?
# 1  
Old 02-20-2008
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.
# 2  
Old 02-20-2008
Java

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.
# 3  
Old 02-21-2008
Awesome, thanks a lot. I'll give it a try.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rename (move) multiple files on remote server using sftp

I want to rename (move) multiple files on remote server. I tried the following command to move all TXT files from my_dir directory to /new_dir. But it does not work. Any help? #!/bin/ksh sftp -dev3 << ABC cd my_dir $(for i in TXT; do echo "ls *.$i" ; rename $x /new_dir/$x;... (1 Reply)
Discussion started by: Soham
1 Replies

2. Shell Programming and Scripting

Move multiple files to different directory using a single command

I have multiple files test1, test2, test3 etc. I want to move to a different directory with ABC_ prefixed to every file and and current dat time as postfix using a single command. (I will be using this is sftp with ! (command for local server). I have tried the following but it gives error ... (5 Replies)
Discussion started by: Soham
5 Replies

3. Shell Programming and Scripting

Move multiple files 4rm Source to different target folders based on a series num in the file content

Dear Experts my scenario is as follows... I have one source folder "Source" and 2 target folders "Target_123456" & "Target_789101". I have 2 series of files. 123456 series and 789101 series. Each series has got 3 types of fiels "Debit", "Refund", "Claims". All files are getting... (17 Replies)
Discussion started by: phani333
17 Replies

4. Shell Programming and Scripting

Sort and move multiple files by modification date

Hi I have a problem, I have a large group of archive files in a folder some are later versions of the same archive, the only difference btween them is that the archiving program we use appends the name with a code for it to keep track of in its data base, and the modification date. I am starting... (6 Replies)
Discussion started by: Paul Walker
6 Replies

5. UNIX for Dummies Questions & Answers

Move Multiple Files adding date timestamp before file type

There are files in a directory and I have to move multiple files adding datetimestamp before the file type. /Data/ abc.csv def.csv ghi.csv I have to move this files to archive directory adding datatimestamp before .csv /archive/ abc_YYYYMMDDHHMMSS.csv def_YYYYMMDDHHMMSS.csv... (7 Replies)
Discussion started by: eskay
7 Replies

6. Shell Programming and Scripting

Script to move files in multiple folders

Hello all, I would appreciate any help to write a script. I have folder A which contains over 30 thousands xml files, I would like create multiple folders and move those files (500 in each folders). Thank you (1 Reply)
Discussion started by: mmsiddig
1 Replies

7. Shell Programming and Scripting

Script to compare substrings of multiple filenames and move to different directory

Hi there, I am having trouble with a script I have written, which is designed to search through a directory for a header and payload file, retrieve a string from both filenames, compare this string and if it matches make a backup of the two files then move them to a different directory for... (1 Reply)
Discussion started by: alcurry
1 Replies

8. Shell Programming and Scripting

To move multiple files to a new folder everytime

Hi , Below is the scenario A.txt B.txt C.csv .......... i want to move all the above files in to a new path & new folder .This folder is created based on date(for ex: today's fodler name will be 20120222).for Everyday move a new folder based on date has to be created & this folder... (1 Reply)
Discussion started by: jagadeeshn04
1 Replies

9. UNIX for Advanced & Expert Users

Move folders from Multiple remote Servers to my local computer

I have 20 Servers (They are Windows 2003) that I remote every day using names or IP address and type in my username & Password then copy folders manually to my local computer. I'm wondering if i can just run script(s) from my local computer to do this job without using FTP(because of security... (5 Replies)
Discussion started by: idiazza
5 Replies

10. Shell Programming and Scripting

Move multiple files

Hi all .. I am trying :- #! /bin/sh # Archives target file ftp'd to SAP ECC srcfiles=/usr/dw/apps/work/PROJECT_NEW/SrcFiles/$1/*.txt tgtfiles=`ls /usr/dw/apps/work/PROJECT_NEW/TgtFiles/FTP/$1/*.txt` for i in $tgtfiles do mv $i /usr/dw/apps/work/PROJECT_HUDSON/archive/Tgt/$1/$i_`date... (3 Replies)
Discussion started by: jmahal
3 Replies
Login or Register to Ask a Question