0

I try to learn how to create crontabs in a remote server.

I try to run a script every 5 minutes.

I use a server in the company "IONOS" and it is in Europe.

I have a Mac. I open the Terminal.

# I go to the server with the authentification. It works well: 
ssh userName@serverName

# I open the default editor. That is Vim:
crontab -e

# I edit the file:
i

# I give my email. If the Cron fails: 
MAILTO=info@example.com 

# Every 5 minutes go to a file where I have a simple script that sends me an e-mail:
*/5 * * * * http://www.example.com/cron-test/1.php  

# save and exit the file
:wq

The Cron does not work. I have received that error in the email that I provided:

/bin/sh: 1: https://www.example.com/cron-test/1php: not found

In that message, the address is a link and the last ":" is included in that link. I do not know if that could be the problem?

Of course, I have checked that if I go to https://www.example.com/cron-test/1php it works well and sends me an email with php.

Please, be aware that I am new to Cron and new with the Terminal. I am just learning and making tutorials.

Nrc
  • 101
  • 3
  • creating a connection from a remote server is a bad practice therefore you can do it with ssh keys exchange & full stack path on both local & remote machines. – francois P Feb 24 '20 at 16:22
  • @francois: I just do not understand – Nrc Feb 24 '20 at 16:45
  • Using cron to access remote server is a bad practice. (server A to server B) The better method is to work locally on server B and push results to server A via ssh (authentication with key for automatization); In your case generate a mail the http server should do the work & for example send logs to the other machine. ; but not act as a trigger from cron on first machine. – francois P Feb 24 '20 at 17:21

1 Answers1

0

Wikipedia states: "The software utility cron is a time-based job scheduler[..]. Users that set up and maintain software environments use cron to schedule jobs (commands or shell scripts) to run [..]."

So, your server is configured to run a command/script every 5 seconds that is named:

'http://www.example.com/cron-test/1.php'

In other words: somewhere within your $PATH an executable command with above name should be found, so that "/bin/sh" could execute this command and send STOUT to your email address.

You have merely provided a URL, but the server doesn't know what you want to do with it.

I think what you try to achieve can be resolved with:

*/5 * * * * /usr/bin/lynx --dump http://www.example.com/cron-test/1.php 

This tells the server to use the lynx command with the --dump option to get the contents of www.example.com/cron-test/1.php and email it to you.

(Execute textbrowser Lynx and dump content of rendered webpage example.com/cron-test/1.php into email to above mentioned address).

John
  • 28
  • 4
  • I have no idea what are you talking about! what is this?: /usr/bin/lynx --dump – Nrc Feb 24 '20 at 19:06
  • 1
    You can not run an URL, you must run a program that fetches that URL: `wget`, `curl` are the most common choices, but `lynx` would also do the job. – Piotr P. Karwasz Feb 24 '20 at 22:15