从cron运行时,无法访问shell脚本中for循环的值

从cron运行时,无法访问shell脚本中for循环的值,shell,parameters,cron,Shell,Parameters,Cron,这是我第一次尝试shell脚本,所以如果我问了一个非常基本的问题,请对我温和一点 我有一个shell脚本,它通过FTP下载一个文件,使用split将文件分解成单独的小文件。然后我使用for循环调用一个PHP文件,该文件对该文件进行了一些处理,这个PHP进程在后台运行,直到完成 当从sudo下的命令行运行时,这个2脚本组合工作得很好,但是当从cron运行时,我似乎无法获得要传递到PHP的文件名值 我的两个测试脚本如下 shell-test.sh #!/bin/bash cd /path/to/d

这是我第一次尝试shell脚本,所以如果我问了一个非常基本的问题,请对我温和一点

我有一个shell脚本,它通过FTP下载一个文件,使用split将文件分解成单独的小文件。然后我使用for循环调用一个PHP文件,该文件对该文件进行了一些处理,这个PHP进程在后台运行,直到完成

当从sudo下的命令行运行时,这个2脚本组合工作得很好,但是当从cron运行时,我似乎无法获得要传递到PHP的文件名值

我的两个测试脚本如下

shell-test.sh

#!/bin/bash

cd /path/to/directory/containing/split/files/

#Split the file into seperate 80k line files
split -l 80000 /path/to/file/needing/to/be/split/

#Get the current epoch time as all scripts will need to use the same update time
epochtime=$(date +"%s")

echo $epochtime

#Output a list of the files in the directory
ls


#For loop to run through each file in the working directory
#For each file we run the php script with safe mode off (to enable access to includes)
#We pass in the name of the file and epochtime
#The ampersand at the end of the string runs the file in the background in parallel so     that all scripts execute concurrently

for file in *
do
php -d safe_mode=Off /path/to/php/script/shell-test.php -f $file -t $epochtime &
done

#Wait for all scripts to finish
wait
shell-test.php

<?php

$scriptOptions = getopt("f:t:");

print_r($scriptOptions);

?>
但是,当通过cron运行时,会输出以下内容

1319825522
xaa
xab
xac
xad
Array
(
[f] => *
[t] => 1319825522
)

因此,我需要知道的是如何将*的值作为文件名而不是实际字符串*(为什么会发生这种情况也会很有用!)。

我随机猜测,为了安全起见,cron正在使用-f选项运行shell。尝试添加

set +f

你的剧本。或者找到其他方法枚举文件。

很好,非常感谢!必须了解在更改此选项的情况下运行cron的影响。有人能推荐一个合适的资源给这个特定主题的相关noob吗?
set +f