I have a bash script which if I run manually (as root) performs all of its tasks without issue. The tasks are just a few php scripts and then a "mv" to move the process file to a temporary folder.

The problem is, when I run the script as a cron job, I get the following error:

mv: cannot stat `/var/sftp/jupiter_sftp/incoming/Yesterday_email_addrs.csv': No such file or directory 

That file definitely exists, so I guess it's a permissions issue, but as it's in root's crontab file I don't understand why it can't see the file. Any ideas?

Thanks in advance!

The script itself:

[root@cartman jupiter]# cat /opt/triggers/jupiter/jupiter_manager_trigger.sh 
php /opt/triggers/jupiter/php/import.php > /var/log/triggers/jupiter_`date +%Y%m%d`_import.log
php /opt/triggers/jupiter/php/update.php > /var/log/triggers/jupiter_`date +%Y%m%d`_update.log
php /opt/triggers/jupiter/php/export.php > /var/log/triggers/jupiter_`date +%Y%m%d`_export.log
php /opt/triggers/jupiter/php/upload.php > /var/log/triggers/jupiter_`date +%Y%m%d`_upload.log
mv /var/sftp/jupiter_sftp/incoming/Yesterday_email_addrs.csv /var/sftp/jupiter_sftp/processed/`date +%Y%m%d`_Yesterday_email_addrs.csv

That "mv" there appears to be the issue. However that file DEFINITELY exists:

[root@cartman jupiter]# ls /var/sftp/jupiter_sftp/incoming/

The import.php file also uses that file and it too can't "see" the file.

Here is the crontab for root:

[root@cartman jupiter]# crontab -u root -l
* * * * * cd /var/www/sugar; php -f cron.php > /dev/null 2>&1
0 10 * * * sh /opt/triggers/jupiter/jupiter_manager_trigger.sh
10 4 * * * sh /opt/scripts/s3backup_www.sh
0 4 * * * sh /opt/scripts/mysql_backup.sh

Here is the relevant part of the import.php file:

$load="LOAD DATA LOCAL INFILE '/var/sftp/jupiter_sftp/incoming/Yesterday_email_addrs.csv' 

So it looks like the issue is still there. Mysql and mv can't "see" the file again today, although it is there:

Sat, 09 Mar 2013 11:00:01 +0000
total 12
-rw-r--r-- 1 jupiter_sftp sftpusers 9590 Mar  9 00:55 Yesterday_email_addrs.csv
-rw-r--r-- 1 jupiter_sftp sftpusers 9590 Mar  9 00:55 /var/sftp/jupiter_sftp/incoming/Yesterday_email_addrs.csv

Here are the errors from the logs:

Data base error. MySQL writes: Can't get stat of '/var/sftp/jupiter_sftp/incoming/Yesterday_email_addrs.csv' (Errcode: 2)

mv /var/sftp/jupiter_sftp/incoming/Yesterday_email_addrs.csv /var/sftp/jupiter_sftp/processed/20130310_Yesterday_email_addrs.csv

mv: cannot stat `/var/sftp/jupiter_sftp/incoming/Yesterday_email_addrs.csv': No such file or directory

I'm almost certain it's a permissions issue. The cron "root" can't seem to "see" those files, but if I move them as root, or run the script as su root, then the script completes correctly.

  • 2
    If it was a permissions error, you'd get an "Permission denied" error, not a "No such file or directory". – mulaz Mar 8 '13 at 11:53

No such file or directory is a clear message that the file isn't found. A permission problem would give one of the following messages:

  • Operation not permitted
  • Permission denied

So please double check your situation and maybe provide more informations, e.g. the relevant source code and crontab entry.

A good idea for debugging your situation is to enrich the jupiter_manager_trigger.sh with the following debug code.

{ date -R
  set -xv
  ls -l /var/sftp/jupiter_sftp/incoming/
  ls -l /var/sftp/jupiter_sftp/incoming/Yesterday_email_addrs.csv
  mv /var/sftp/jupiter_sftp/incoming/Yesterday_email_addrs.csv /var/sftp/jupiter_sftp/processed/`date +%Y%m%d`_Yesterday_email_addrs.csv
  set +xv
} >>/tmp/debug_jupiter.out

On this way you ensure that at the invocation time the file is existing and in what state it is.

  • Updated the original post with further details – Adrian Mar 8 '13 at 12:42
  • Please try the approach above to debug your situation. – H.-Dirk Schmitt Mar 8 '13 at 14:07
  • So what was the problem ? Don't forget to close the question. – H.-Dirk Schmitt Mar 8 '13 at 16:38
  • Well, I don't know for certain yet as I reduced the cron job to just your suggested debug command. I'll setup a proper full test (with the php tasks) and I'll let you know if it works. – Adrian Mar 8 '13 at 16:50
  • I think it's all working now - not sure how, but your debug code seems to have fixed it, so I'm keeping it! Thanks for all your help! :) – Adrian Mar 8 '13 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.