Pattern not working in Cron script

Hi,

I have written a shell script to list all the files with some pattern as below.
<CODE> ls *_20151201*.txt <CODE>

its working properly when ran manually. But when i tried to run by cronning it.. its throwing an error that no files exists with file name *_20151201*.txt

But when I try with *.txt its working fine. What is the issue with using pattern here

Please help if you are aware of this error.

What's the output of ls *.txt ? Does it contain files matching your pattern? As cron doesn't have your usual environment by default, you need to explicitly set it, e.g. by running your .profile script.

1 Like

Hello ssk250,

You should give complete path with command for which you want to show files as follows.

My/actual/path/ls *_20151201*.txt

Could you please try above within your crontab entry(which you haven't mentioned in your post) or in your script and let us know if this works, it is always good practice to mention complete paths in crontab entries.

Thanks,
R. Singh

1 Like

Yes the problem is I havent given the full path as I assumed that the script will check in the same path where it is present. Thats the reason why it worked when ran manually. But not in Cron.

Thanks for the quick help for both of you...