Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Renaming Multiple Folders on Server

Posted on 2004-08-20
9
Medium Priority
?
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 1000 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

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

670 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