Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

wget in script not working when called from cron

I’ve read a load of similar cases and can’t for the life of me figure this one out…

I’m running a wget command inside a .sh script which is called from cron on reboot as follows:

@reboot /home/user/reboot_script.sh

The .sh script starts with

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#!/bin/bash

And I have done chmod +x reboot_script.sh

The line that fails is :

Either

mac=$(</home/user/mac.txt)

Which may not be providing the content to the variable in the wget

OR

/usr/bin/wget "http://my.domain.com/$mac/line.txt" -O /home/user/line.txt 

If I run the script from command line, it works absolutely fine but if it runs from the cron on reboot, the script runs, but line.txt is saved as an empty file (0 bytes). Again, if run directly from command line, it works fine.

I’ve looked at file permissions, absolute paths, everything I can think of, but I’ve been staring at this for hours now.

Any help would be appreciated. Thanks.

>Solution :

@reboot is too early in boot process IMHO. You should create a systemd script to wait network.

As a workaround, you can add a

sleep 30

or better:

until ping domain.com; do
    sleep 5
done

before your wget

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading