File created in a different location instead of desired location on using crontab

Hi,

I am logging to a linux server through a user "user1" in /home directory.

There is a script in a directory in 'root' for which all permissions are available including the directory. This script when executed creates a file in the directory.

When the script is added to crontab, on execution, the file gets created in /home/user1. (When manually the script is run from the directory, it works fine.)

I want the file to be created in the directory where the script exists. Could you please provide me a solution to this?

Thanks,
Archana

When being executed via cron, there will not be the same environment like when you execute it interactive in the shell with your user. Variables will not be set, PATH will be different and so on.
Here is a very good article about it: