Need for loop to get dirs and run bash script
Greetings all!
This is my first post. I hope it's in the appropriate section. I have to format 4 years worth of awstats data "static" for a client and then move it to their new server. I don't want to run the commend to do this 48 times. If possible I would like to use a bash script that uses the folders in a directory so the script knows which year-month to do this for me and which folder to place the output in. The command I need to run is as follows; Code:
perl /usr/share/awstats/awstats_buildstaticpages.pl -month=12 -year=2006 -config=domain.org -awstatsprog=/var/www/cgi-bin/awstats/awstats.pl -dir=/root/static_awstats/ Code:
/root/static_awstats/2006-12 I've already created the folders needed for the timeframe I need to use. So my question is. Can I use the folders that I have created to run the command in a for loop to get all the pages done. Example of my static_awstats dir; Code:
/root/static_awstats I hope this question makes sense to everyone. Thanks for any suggestions. |
Sure you just need to iterate numbers. This should do the whole of 2006 though 2010 inclusive:
Code:
for year in $(seq 2006 2010);do for month in $(seq -w 1 12);do perl /usr/share/awstats/awstats_buildstaticpages.pl -month=${month} -year=${year} -config=domain.org -awstatsprog=/var/www/cgi-bin/awstats/awstats.pl -dir=/root/static_awstats/${year}-${month};done;done That's all one line which isn't nice to look at of course. If you want to look at it in a more readable form then paste it in to a text editor then replace the ; with line breaks |
arizonagroovejet,
This works perfectly thank you very much. I've learned allot just from that and managed to automate almost everything else I wanted from this example. I have one final question that I'm stuck on and it seems so simple. I now need to symlink the base awstats.domain.org.html inside each folder to index.html to complete the conversion. From the base folder outside all the year-month folders I'm using the following; Code:
for i in `ls`;do ln -s awstats.domain.org.html index.html "$i";done Code:
lrwxrwxrwx 1 root root 10 Jul 7 13:36 index.html -> index.html Thanks again for your help. That taught me allot and saved me a ton of time. Bill |
Assuming you want to end up with an index.html file in each of the ${year}-${month} directories then in the directory where those ${year}-${month} directories are located do
Code:
$ for i in *; do ln -s awstats.domain.org.html "${i}/index.html";done |
Your assumptions are correct. That worked perfectly. Thank you so much. I hope I can help someone here in the future.
|
Quote:
|
All times are GMT -5. The time now is 05:10 PM. |