E
E
Evgeny Ivanov2018-12-03 07:51:11
linux
Evgeny Ivanov, 2018-12-03 07:51:11

Why does the script not work via cron (sh->php)?

This is how the script works fine
crontab -e

*/1 * * * * /usr/bin/php  /var/www/site/get_data.php >/dev/null 2>&1

(The script writes data to the database.)
But it was necessary to run the script more than once a minute.
Advised to do through sh
crontab -e
*/3 * * * * /var/www/site/get_data.sh >/dev/null 2>&1

get_data.sh
#!/bin/bash
for i in {1..10}
do
/usr/bin/php  /var/www/site/get_data.php >/dev/null 2>&1
sleep 10
done

And the script doesn't work. The data does not appear in the database.
Why is the script not working?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Korobkov, 2018-12-03
@logpol32

Judging by the comment: Why doesn't the script work via cron (sh->php)?
The problem is that you saved the file on Windows.
It's good to read about crlf and lf.
Problem solution:
The script is small, you can rewrite it directly on Linux with your hands (for example, in nano)
Or try using the solution from here:
stackoverflow

awk '{ sub("\r$", ""); print }' get_data.sh > get_data2.sh
mv get_data2.sh get_data.sh

R
Radjah, 2018-12-03
@Radjah

Instead of writing the output to null, write it to the file. Also, cron can throw something into the system logs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question