Passing arguments to a shell script from file while scheduling in cron

Hi,

I have a shell script Scp_1.sh for which I have to pass 2 arguments to run.

I have another script Scp_2.sh which in turns calls script Scp_1.sh inside.

How do I make Scp_1.sh script to read arguments automatically from a file, while running Scp_2.sh?

--

Weblogic Support

You're thinking backwards. scp_1.sh should simply expect two arguments all the time. scp_2.sh should read the arguments from a file and pass them to scp_1.sh. Something like this:
#! /usr/bin/ksh
read arg1 arg2 < /path/to/a_file
/path/to/scp_1.sh $arg1 $arg2
exit $?

$? is the exit code from scp_1, so that "exit $?" just makes scp_2.sh duplicate scp_1.sh's exit code.

1 Like

Thanks for the reply.

So from what I understand

if Scp_1.sh expects two arguments line arg1=env (for eg: UAT) and arg2=path (for eg: /var/tmp)

so the content of file from which the script reads should be of bfelow ormat

cat filename.txt
UAT /var/tmp

(UAT then space & PATH)

Please correct me on this.

--

Weblogic Support

Yes that would be the correct format of filename.txt because IFS is set to a space. If IFS were a colon ":" filename.txt would be

cat filename.txt
UAT:/tmp

Thanks a lot !!

--

Weblogic Support