Solved

Renaming Multiple Folders on Server

Posted on 2004-08-20
9
166 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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