0

I've been tying to solve this issue but had no luck so far:

  • I have a script that captures some WIFI statistics from a raspberry pi.
  • the script runs fine when I execute from the terminal when using python network_test.py
  • script fails when I schedule a cron job using another python script:

python script to schedule job

from crontab import CronTab
cron = CronTab(user=True)

job  = cron.new(command='cd /home/pi4/Documents/WIFI_Scan && /usr/bin/python /home/pi4/Documents/WIFI_Scan/network_test.py >> /home/pi4/Documents/WIFI_Scan/out.txt 2>&1')
            job.minute.every(1)
            
for job in cron:
print(job)
            
cron.write()

- the script runs but i get the error below when I look at the out.txt file:

Traceback (most recent call last):
  File "/home/pi4/Documents/WIFI_Scan/network_test.py", line 57, in <module>
    print(subprocess.check_output(['iwgetid']).decode())
  File "/home/pi4/Documents/WIFI_Scan/subprocess.py", line 424, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/home/pi4/Documents/WIFI_Scan/subprocess.py", line 505, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/home/pi4/Documents/WIFI_Scan/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/pi4/Documents/WIFI_Scan/subprocess.py", line 1823, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'iwgetid'

  • here is the network_test.py script
import subprocess

output = subprocess.check_output(['iwgetid']).decode()
print(output)

I've tried many things but no luck..

Tried moving the script to the main python folder. tried using a bash file to start the script from cron but nothing

Fernandez
  • 1
  • 1

0 Answers0