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
Solved

Renaming Multiple Folders on Server

Posted on 2004-08-20
9
164 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Magento error 9 75
XAMPP 14 48
file path 14 71
NGINX/Plesk  subdomain allow only 5 select ip addresses, deny everyone else 2 94
As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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