Find the answer to your Linux question:
Results 1 to 6 of 6
OK Ive looked around but can't seen to find the answer. I want to combine several scripts into one. I can do it by putting all the scripts into 1 ...
  1. #1
    Linux Newbie
    Join Date
    Jun 2006
    Posts
    139

    EZ question on cmds and files

    OK Ive looked around but can't seen to find the answer.
    I want to combine several scripts into one.
    I can do it by putting all the scripts into 1 file and execute it.
    BUT can I have a script/file that executes all the scripts I want to combine?

    thanks
    mace

  2. #2
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    Quote Originally Posted by mace View Post
    OK Ive looked around but can't seen to find the answer.
    I want to combine several scripts into one.
    I can do it by putting all the scripts into 1 file and execute it.
    BUT can I have a script/file that executes all the scripts I want to combine?

    thanks
    mace
    I'm not exactly sure what you're asking, but here goes. Yes, you can write a shell script that runs a series of commands. Those commands can be other scripts. For example:

    Code:
    #!/bin/bash
    
    nameofscript1
    nameofscript2
    nameofscript3
    nameofscript4
    Registered Linux user #270181
    TechieMoe's Tech Rants

  3. #3
    Linux Newbie
    Join Date
    Jun 2006
    Posts
    139
    Thanks TM but now I have another question, which I should have asked before.
    Each preceding scripts needs the previous script to finish( s1 is a shutdown, s2 is a backup/zip of s1, and s3 is the restarting of the db)

    I know I can put a sleep in between each script name but that dosen't ensure the previous step finished.

    How can I overcome this?

    thanks
    Mace

  4. #4
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    Quote Originally Posted by mace View Post
    Thanks TM but now I have another question, which I should have asked before.
    Each preceding scripts needs the previous script to finish( s1 is a shutdown, s2 is a backup/zip of s1, and s3 is the restarting of the db)

    I know I can put a sleep in between each script name but that dosen't ensure the previous step finished.

    How can I overcome this?

    thanks
    Mace
    That's a good question, to which I do not know the answer. Hang in there; I'm sure someone else does.
    Registered Linux user #270181
    TechieMoe's Tech Rants

  5. #5
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    I experimented on this problem.
    main.sh
    Code:
    #!/bin/bash
    ./first.sh
    ./second.sh 
    exit
    first.sh
    Code:
    #!/bin/bash
    i=0
    while [ "$i" -lt 3 ]
    do
      echo "first"
      sleep 2
      i=`expr $i + 1`
    done
    second.sh
    Code:
    #!/bin/bash
    i=0
    while [ "$i" -lt 3 ]
    do
      echo "second"
      sleep 2
      i=`expr $i + 1`
    done
    When I executed main.sh, output is
    Code:
    first
    first
    first
    second
    second
    second
    It means, second.sh got executed only when first.sh exited.
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  6. #6
    Linux Newbie
    Join Date
    Jun 2006
    Posts
    139
    Thank you. I'll give it a shot today

    mace

Posting Permissions

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