Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to call a KSH script a KSH script.

Script 1 performs the following:

  1. Loops thru a list of database server
  2. Perfroms a query
  3. Appends output from query from each database server to a txtfile

Script 2 performs the following:

  1. Creates an HTML file that displays the each row in the text file in an HTML File

  2. Emails the HTML file with the query results to a list of receipeints

    Usage: KSH backup_report.ksh qry_rslt_textfile.txt
    (txtfile contains results of query from each server)

Is the following syntax correct?

#! /bin/ksh
< Start of Script 1 Code>
.
.
.
< End of Script 1 Code>

< Start of Script 2 Code - Call Script 2>
/sybase/dba/backup_report.ksh qry_rslt_textfile.txt
<End of Script 2 Code>
share|improve this question

2 Answers 2

Yes - providing that the script has execute permission, this will do what you want. It will in actuality call the second script as the last command of the first script, but that's splitting a technical hair that you're probably not going to need to worry about.

share|improve this answer

To call a script from another program (or script), you must take care of a list of things:

  1. The script must be found
  2. The script must have execute permissions
  3. The script must include a hint to its interpreter

Finding the script

Check. You've already included the full path to the script. An alternative is to include /sybase/dba in the PATH variable at the top of script 1:

PATH=/sybase/dba:$PATH

Correct permissions

The script will need execute permissions for all categories of users that may need to run it.

For most interpreters execute permissions are not sufficient; the chosen interpreter also needs to be able to read the script's code.

$ ls -l  /sybase/dba/backup_report.ksh
-rwxr-x---   1 Henk     sys           805 Apr  3 07:00 /sybase/dba/backup_report.ksh

The right interpreter

Scripts are not executed directly. The kernel needs a hint to tell it which interpreter to use. This is accomplished by including a #! (hashbang) mark on the first line, followed by the path to the interpreter:

#! /bin/ksh

Assure you know where your ksh lives and insert the right path.

Final Note

Also make sure you know which version of ksh. These days, ksh implies ksh93, which is still actively developed and available on most platforms.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.