简体   繁体   English

云服务器centos上的cpanel shell脚本无此文件或目录

[英]cpanel shell script on cloud server centos no such file or dir

I have a shell script copy_files.sh which I call once a day using a cron job. 我有一个shell脚本copy_files.sh,我每天使用cron作业调用一次。

However it has never worked I keep getting no such file or directory. 但是它从来没有奏效,我一直没有得到这样的文件或目录。

!#/bin/sh
for f in /home/site1/public_html/admin/data/*.csv
do 
  cp -v "$f" /home/site2/app/cron_jobs/data/"${f%.csv}".csv
done

I have checked via ssh that all paths are correct I have varified the path to /bin/sh using ls -l /bin/sh I have set perms and user and group to root for copy_files.sh I have disabled php open_basedir protection. 我已经通过ssh检查了所有路径都是正确的,我已经使用ls -l /bin/sh了/ bin / sh的路径,我已经将perms以及user和group设置为root for copy_files.sh我已经禁用了php open_basedir保护。

the shell script is in /home/site2/ Shell脚本位于/ home / site2 /

Any ideas why I am still getting no such file or directory? 任何想法为什么我仍然没有得到这样的文件或目录? Is there anyway to check open_basedir protection is off that said considering the script is owned by root I don't see that being the problem unless it's executed as site2 user and not root? 无论如何,是否有必要检查open_basedir的保护,说考虑到脚本是由root拥有的,除非它是作为site2用户而不是root用户执行的,否则我认为这不是问题吗?

Because of the way you use shell expansion, the variable in your for loop contains the absolute path to your files. 由于使用Shell扩展的方式,for循环中的变量包含文件的绝对路径。 Having the absolute path, means there is no need to use string manipulation (%) nor do you need to add the ".csv" to the filename, just get rid of it all together and provide the directory to which you're copying as your second argument to cp, see the example below. 具有绝对路径,这意味着无需使用字符串操作(%),也无需在文件名中添加“ .csv”,只需将其全部删除并提供要复制到的目录即可cp的第二个参数,请参见下面的示例。

#!/bin/sh for f in /home/site1/public_html/admin/data/*.csv; do cp -v "$f" /home/site2/app/cron_jobs/data done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM