Solved

Renaming Multiple Folders on Server

Posted on 2004-08-20
9
158 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
Comment Utility
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
Comment Utility
# 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
Comment Utility
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
 

Author Comment

by:timshank
Comment Utility
ahoffmann,

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

Thanks
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
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
Comment Utility
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
Comment Utility
aha, path guessing was part of the question ...
0
 

Author Comment

by:timshank
Comment Utility
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
Comment Utility
thanks for explanation.
It's ok to grade the working solution ;-)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now