Tzahi Kadosh
Tzahi Kadosh

Reputation: 407

how to schedule .sh script on linux server?

I'm new to linux, and I have linux server with script ftp.sh which transfers files to windows server.

I have tried to schedule it at 06:15 every day via crontab command in PUTTY/winSCP

 15 06 * * * sh ftp.sh 

and get this error message:

command not found

I have also tried to schedule it from a Windows batch file with

start folderName\putty.exe -ssh root@10.*.*.* 22 -pw "password"

It succeeds with the login, but can't execute navigation to /opt/dan/scripts or execute the sh ftp.sh command in it.

What am I doing wrong? Is there another way I havn't thought about?

Upvotes: 0

Views: 813

Answers (3)

Read more about the PATH variable. It is not the same in interactive shells (they usually set it in your ~/.bashrc) and in cron jobs.

So specify an absolute path for your ftp.sh shell script in your crontab and start that script with a shebang like #!/bin/sh

BTW, consider switching to Linux entirely (e.g. by installing some Linux distribution on your laptop)

Upvotes: 0

The Pizza Overlord
The Pizza Overlord

Reputation: 136

Your OS doesn't seem to recognise 'sh' as a command, as stated here:

command not found

This usually means it's not installed on the particular flavour of Linux you're using. You should use a different file interpreter, or if you're sure that 'sh' is installed then you should use the absolute path to that program in the cron command.

If you type the following in to a terminal session, it should bring up the full path:

whereis sh

Or alternatively:

which sh

Upvotes: 1

Matthias
Matthias

Reputation: 3556

sh cannot execute ftp.sh since ftp.sh is propably not in the PATH environment variable. If you write the full path to ftp.sh you may succeed.

15 06 * * * sh /the/path/to/ftp.sh

Or depending on your setup

15 06 * * * /path/to/sh /the/path/to/ftp.sh

Or

15 06 * * * /the/path/to/ftp.sh

Upvotes: 1

Related Questions