Find the answer to your Linux question:
Results 1 to 2 of 2
This is it right here, it looks simple enough, prolly too simple. 1. This script will create directories for a specific datatype. Example rickk, rik, rikky etc. 2. This script ...
  1. #1
    Just Joined!
    Join Date
    May 2010
    Posts
    1

    need help with a script

    This is it right here, it looks simple enough, prolly too simple.

    1. This script will create directories for a specific datatype. Example rickk, rik, rikky etc.
    2. This script will aslo create subdirectories labeled by the duration of an event. For example if an event where to take place for 5 days, May 5 - 10th. Folders will be labled: 20100505, 20100506, 20100507, etc will be included in each datatype. Since this exercise will take 6 days there will be 6 subdirectories under each datatype.
    3. This script will also create cgi scripts for each of the dataype and day of the the exercise. For example dataype "rik" for May 09 will read rik5.cgi, since May 09 is the 5th day of the exercise.

    This is how it looks so far, it works great but I realized that if and when I plan to add more datatypes that its going to involve alot of repetivie typing. I figure to simplify this whole thing would be best to use loops. Can someone direct me to some good information concerning loops and sample of loops? I have a feeling that what I need to do is going to involve a nest of loops.

    #!/bin/ksh


    root_dir=/opt/global/webservices/apache/app/test/dynamic/
    cd $root_dir

    mkdir rickk
    mkdir rik

    data_dir=$root_dir/rickk
    cd $data_dir

    for i in 05 06 07 08 09 10
    do
    date_dir="201005"${i}
    mkdir $data_dir/$date_dir
    done

    for d in 1 2 3 4 5 6
    do
    touch $data_dir${d}.cgi
    done

    data_dir=$root_dir/rik
    cd $data_dir

    for i in 05 06 07 08 09 10
    do
    date_dir="201005"${i}
    mkdir $data_dir/$date_dir
    done

    for d in 1 2 3 4 5
    do
    touch $data_dir${d}.cgi
    done

    cd $root_dir
    chmod 777 -R *

  2. #2
    Just Joined!
    Join Date
    Sep 2004
    Posts
    9
    You are already familiar with the the for-loop, I suggest you put all the create dir/file stuff in such a loop.
    In the loop, test for the existence of the dirs/files before you try to create them.

    Create a variable before the loop, containing the datatypes to loop over.
    This could be a list such as "a b c", or perhaps users on the system, extracted from /etc/passwd, /home/* or whatever seems appropriate.

    Replace you rick and rik with the new variable name.

    I also think you'd want to check your touch command, and perhaps add a slash in between the dirname and filename?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...