0

I have this shell script at /usr/local/1.sh:

#!/bin/sh
wget -r -np --user=peter --password='123' ftp://67.225.87.95/ -p /test/

If I run it using

# sh 1.sh 

the script executes ok and does what its supposed to do.

But if I create a cron job to execute the exact same script:

1 2 * * * /usr/local/bin/1.sh

the script is not executed at all.

What could be wrong?

Sunny
  • 5,834
  • 3
  • 22
  • 24
user86187
  • 33
  • 1
  • 5

3 Answers3

2
  • Always use the full path when doing something in cron job
  • Redirect all the output, error to a log file to see what happen: 1 2 * * * /usr/local/bin/1.sh > /var/log/1.log 2>&1
quanta
  • 51,413
  • 19
  • 159
  • 217
2

If you are going run it directly without invoking the shell interprer, you need to provide the appropriate permissions:

chmod +x /usr/local/bin/1.sh

Otherwise, run the interpreter against its:

1 2 * * * /bin/sh /usr/local/bin/1.sh
Rilindo
  • 5,078
  • 5
  • 28
  • 46
0

Replace:

1 2 * * * /usr/local/bin/1.sh

By:

1 2 * * * /bin/bash /usr/local/bin/1.sh

or

Keep it:

1 2 * * * /usr/local/bin/1.sh

And prepend the following to /usr/local/bin/1.sh:

#!/bin/bash

(you may need to replace /bin/bash by whatever which bash is telling you)

cutsoy
  • 101
  • 2