Cron entry to pass the value to script

0

I have a script(main.sh) which calls another script(Get_Files.sh) and gets a value in a variable like the below:

File_to_Refresh="$(sh /Aug/work/Get_Files.sh /Aug/Work/Universal_File.txt)" 

Now I have to schedule the script main.sh for 3 different files i.e. the Universal_File.txt with 3 different values and on 3 different days.

So, to make the script generic, I want to pass the Universal file to Get_Files.sh from the Cron Entry only.

How Can i achieve the same?

Below is working if I run the script manually like sh /Aug/Work/main.sh /Aug/Work/Universal_File.txt but it's not working when i run it through cron.

File_to_Refresh="$(sh /Aug/work/Get_Files.sh "$1")"

Cron :

45 08 * * * sh /Aug/Work/main.sh /Aug/Work/Universal_File.txt

Hi,

I suspect that your cron job is working correctly, in that it will spawn a shell and close. You should be able to see out put in your local mail "Q".

Try running the shell script on it's own as follows;

45 08 * * * /Aug/Work/main.sh /Aug/Work/Universal_File.txt

But I suspect that you may have to take your input file and call from inside your shell script.

Regards

Gull04

2 Likes

Yes, it works. The argument /Aug/Work/Universal_File.txt lands in $1 .
The prefixed sh allows the /Aug/Work/main.sh to not be executable.

1 Like