Solved

Renaming Multiple Folders on Server

Posted on 2004-08-20
9
162 Views
Last Modified: 2010-03-04
I hope that this is the right place to post this question

I have 5 folders named 1 2 3 4 and 5

Once every 12 hours I would like to rotate the folder names. 1 would become 2, 2 would become 3, 5 would become 1, etc.

Is there a way to do this using cron?

How would I do it?
0
Comment
Question by:timshank
  • 4
  • 3
  • 2
9 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 11855338
Yes this can be done via cron

my crontab -l :
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.19956 installed on Fri Aug 20 21:57:23 2004)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
* * * * * export MPATH=/your/path/where/the/dirs/are; mv $MPATH/5 $MPATH/t; for i in 4 3 2 1; do mv $MPATH/$i $MPATH/$(( i + 1 )); done; mv $MPATH/t $MPATH/1

to edit your contab use

crontab -e
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 11855459
# add to crontab
0 0,12 * * * /bin/awk 'BEGIN{for(i=5;i>0;i--){print "mv "i" "i+1}print "mv 6 1"}'|/bin/sh
0
 

Author Comment

by:timshank
ID: 11862237
hernst42,

I keep getting the error

mv: can't stat source /public_html/zdetcom/includes/6
mv: can't stat source /public_html/zdetcom/includes/5
mv: can't stat source /public_html/zdetcom/includes/4
mv: can't stat source /public_html/zdetcom/includes/3
mv: can't stat source /public_html/zdetcom/includes/2
mv: can't stat source /public_html/zdetcom/includes/1
mv: can't stat source /public_html/zdetcom/includes/t

What can I do to correct that? Thanks
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:timshank
ID: 11862250
ahoffmann,

where in your line of code do I put the path to my directory? the path being public_html/zdetcom/includes/

Thanks
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 11862953
0 0,12 * * * cd /public_html/zdetcom/includes/ && /bin/awk 'BEGIN{for(i=5;i>0;i--){print "mv "i" "i+1}print "mv 6 1"}'|/bin/sh
0
 
LVL 48

Accepted Solution

by:
hernst42 earned 250 total points
ID: 11863113
Is /public_html/zdetcom/includes/ the absolute path where the files are stored on the server or is that path relative to your home-directory, maybe the path must be more something like:
/home/timshank/public_html/zdetcom/includes/

you can get that path if you make ca cd to that includes directory and then do a
# pwd
The output of that command is the path you have to use.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 11865089
aha, path guessing was part of the question ...
0
 

Author Comment

by:timshank
ID: 11865435
Actually I tried both yours and hernst42s response.

I ended up with an additional error with yours so I awarded the points to hernst42.

/bin/sh: line 1: 0: command not found

Sorry. I appreciate the help but I can only accept one comment as the answer.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 11865442
thanks for explanation.
It's ok to grade the working solution ;-)
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CentOS 7 (Apache2) Cannot Install SSL Cert 1 62
HHTP and HTTPS redirect question 3 113
Stream live video from Raspberry Pi camera 22 162
setup wamp server for first time 2 74
Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question