Results 1 to 2 of 2

Thread: HP-UX shell script to run file saved on different subdirectories

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default HP-UX shell script to run file saved on different subdirectories

    Trying to run files save in different subdirectories HP-UX. The files I am trying to run are named the same. e.g. directory/subdiretory0/panthers; directory/subdiretory1/panthers;directory/subdiretory2/panthers;directory/subdiretory3/panthers
    Would like to loop thru each subdirectory and run the file 'panthers'. Save the output in another subdiredory lion e.g. directory/subdiretory0/lion;directory/subdiretory1/lion;directory/subdiretory2/lion;directory/subdiretory3/lion
    I have no experience in shell scripting. thanks

  2. #2
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,500
    Thanks
    17
    Thanked 790 Times in 507 Posts
    Rep Power
    10

    Default

    Use ksh for loop. Create a script called script.sh
    Code:
    #!/usr/bin/ksh
    dirs="/path/to/dir1 /path/to/dir2 /path/to/dir3"
    for d in $dirs; do
       command-name >$d/file.txt
    done
    Run it as follows:
    Code:
    chmod +x script.sh
    ./script.sh
    KSH For Loop Examples
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [Solved] Shell script to convert log file into a csv formatted text file
    By c00l_chintu in forum Shell scripting
    Replies: 13
    Last Post: 28th September 2012, 12:24 AM
  2. [Solved] Shell script for ftp the file
    By vishal_titre in forum Shell scripting
    Replies: 4
    Last Post: 21st August 2009, 03:50 PM
  3. Replies: 2
    Last Post: 28th June 2009, 09:10 PM
  4. Replies: 1
    Last Post: 25th August 2008, 02:39 PM
  5. Replies: 2
    Last Post: 31st May 2008, 06:44 PM

Tags for this Thread

Posting Permissions

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