How to execute korn shell script from different directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to execute korn shell script from different directory
# 1  
Old 12-15-2011
How to execute korn shell script from different directory

Guy's ,
I need to run korn shell script from different directory, usually I run the script using ./details.ksh in the same directory but now I need to run the file and process details using awk code.
Now I am running the script this way but with no luck

HTML Code:
  Directory = home/users/work 
HTML Code:
    ${Directory}/details.ksh| awk '
      {
          gsub( ">", "" );        # strip uneeded junk and make "foo bar" easy to capture
          gsub( " ", "~" );
          gsub( "<", " " );
   
          for( i = 1; i <= NF; i++ )          # snarf up each name=value pair
          {
              if( split( $(i), a, "=" ) == 2 )
              {
                  gsub(  "\"", "", a[2] );
                  gsub(  "~", " ", a[2] );
                  values[a[1]] = a[2];
              }
          }
   
          #gcount[values["Gender"]]++;         # collect counts
          #acount[values["Age"]]++;
          agcount[values["Gender"]","values["Age"]]++;
   
          printf( "%s %s %s %s\n", values["NAME"], values["Age"], values["D.O.B"], values["Gender"] );
      }
   
      END {
          printf( "\nSummary\n" );
          for( x in agcount )
              printf( "%s,%d\n", x, agcount[x] ) | "sort";
      }
  ' input-file
     
This code is in different directory i.e.

HTML Code:
home/TestDir/awkwork 
Can I please get help with this?
Any help is appreciated.
# 2  
Old 12-15-2011
If you have execute permissions on the script you should be able to run it.
It looks like your missing the first "/" in your path.. Try
Directory="/home/users/work/"
This User Gave Thanks to BeefStu For This Post:
# 3  
Old 12-16-2011
Thank you BeefStu,

The problem was with the file permission, but is there a way to change output file permission within the the code.

HTML Code:
chmod 777 the output file within the code. 
# 4  
Old 12-16-2011
you can try running this way... may not need to use chmod..


ksh /home/TestDir/awkwork/details.ksh


[@CentOS1 ~]$ pwd
/home/xxx
[@CentOS1 ~]$


[@CentOS1 ~]$ sh /tmp/sh.sh
hello


[@CentOS1 ~]$ cat /tmp/sh.sh

echo "hello"

-rw-r--r-- 1 binku users 15 Dec 15 06:05 /tmp/sh.sh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute sql statment in korn shell

I am fairly new to writing scripts, and have gotten a lot of help from this site in the past with many of the posts. I have a question/issue with a script I am attempting to write and have a question regarding executing an sql statement inside of a loop (do while). I have in the past written... (1 Reply)
Discussion started by: josbor01
1 Replies

2. Shell Programming and Scripting

Help with korn shell script to get the latest file versions in a directory

I want to write a korn shell script to get the latest three versions for a file in the directory having lot of files with various versions (files with prefix as same but time stamp as suffix) and compress it and at the same time have to remove the remaining versions of the file (other than latest... (4 Replies)
Discussion started by: maheshbabu
4 Replies

3. Shell Programming and Scripting

how do i execute nohup and background job inside the korn script for db2

load_cursor_stmt() { ls /db/admin/ddl/rmn01000/load_cursor*.sql|while read file do echo "${file}" `nohup db2 -tvf "$file" \&` done }Error: ------- /admin/ddl/rmn01000/load_cursor5.sql /db/admin/ddl/rmn01000/load_cursor6.sql + read file + echo... (3 Replies)
Discussion started by: Hangman2
3 Replies

4. Shell Programming and Scripting

MKS KORN SHELL WONT EXECUTE from windows command prompt

Can anybody help me with this small script , the script works fine and launches the IE from c:\documents and settings \test\my documents>ksh prompt $RunURL1.sh this scitpt works and launches the ie from ksh , but when i schedule it to run the script then i get the error box saying command:1... (2 Replies)
Discussion started by: venu
2 Replies

5. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

6. Shell Programming and Scripting

how to take absolute pathname to a directory in korn shell

how to take absolute pathname to a directory in korn shell (2 Replies)
Discussion started by: babuda0059
2 Replies

7. Shell Programming and Scripting

How to execute script on files in another directory?

Hi Guys, Is there any way I can execute my bash script on files in a different folder than what the script is in? Here is an excerpt of my script: #!/usr/bin/bash input_path="/cygdrive/c/files" output_path="/cygdrive/c/files/data" #script uses files from /cygdrive/c/files directory,... (1 Reply)
Discussion started by: npatwardhan
1 Replies

8. AIX

Help with Korn Shell script

I have this Korn shell script that runs via a cron entry. It runs in a loop "watching" a specific file system for files with a certain name. The file system that it is watching is an upload file system for an FTP server. When files that are the correct name come in, it takes the extension of the... (1 Reply)
Discussion started by: heprox
1 Replies

9. UNIX Desktop Questions & Answers

korn shell script

hi all i am writing the korn shell script. i have a SQL script which gives me the folowing output DSA.WLG.20050713211544.20051025.20050713211544 28991 1130198400 DSA.WLG.20050713211544.20051025.20050713211544 25881 1130198400 DSA.WLG.20050711210100.20051025.20050711210100 25881 ... (3 Replies)
Discussion started by: pavan_test
3 Replies

10. UNIX for Dummies Questions & Answers

korn shell script

hello., i have 2 files.. 1 file is in this folder /home/test/ssk/DSA.WLG.20050713211544.20050710.20050713211544 (this part) other file is in this folder /home/kk/dev/DSA.WLG.20050711210100.20050710.20050711210100 ... (1 Reply)
Discussion started by: pavan_test
1 Replies
Login or Register to Ask a Question