0

I'm facing a strange problem. I have a Python script that includes the following line

  subprocess.call("ifconfig ens3 inet6 add " + str(address) + "/64", shell=True)

It assigns a ip to the OS in a loop. The problem I'm facing is that the IPs get assigned if I manually run it, but the IPs don't get assigned when I run it with cron at reboot. I do know the script does run at boot because I send the results to a log. But when I check with ip -6 addr the IPs are not assigned if the script ran with cron. But they are assigned if I run it myself.

Arya
  • 8,473
  • 27
  • 105
  • 175
  • 2
    Cron sometimes doesn't have a `$PATH` variable, and thus cannot find the location of `ifconfig`. Have you tried replacing it with `/sbin/ifconfig` (or wherever `ifconfig` may be)? – Nils Werner Oct 18 '17 at 15:08
  • I will try that – Arya Oct 18 '17 at 15:11
  • It worked. You can write it in the answer and I will accept it – Arya Oct 18 '17 at 15:15
  • Possible duplicate of [Unable to run a service command via cron](https://stackoverflow.com/questions/8127433/unable-to-run-a-service-command-via-cron) – SiHa Oct 18 '17 at 15:41

1 Answers1

0

Cron sometimes doesn't have a $PATH variable set, and thus cannot find the location of ifconfig. Replace it with /sbin/ifconfig (or wherever ifconfig may be).

Nils Werner
  • 34,832
  • 7
  • 76
  • 98
  • Technically, I believe `cron`, and pretty much every other process on a system, with the exception maybe of `init` and some other early boot things, will have a `PATH` variable available to it. It certainly does on my system, when I look at `/proc//environ`. It's more correct to say that the contents of that `PATH` variable are often not what a user expects. – twalberg Oct 18 '17 at 16:32