Issue with AOS command called from cronjob

Post Reply
HStr
Member
Posts: 8
Joined: 21 Apr 2022 05:20

Issue with AOS command called from cronjob

Post by HStr »

Hello,

I want to call AOS commands at an intervall. That's why I've created a python script and added it to a cronjob. The script is called by cronjob as expected (checked by updated content of cron.log). But the execution of AOS command (os.popen(cmd).read()) is not working, an exception is not thrown. However, if I call the python script manually from CLI the AOS command is executed as expected.

The python script /flash/python/cron.py:
#!/usr/bin/env python3

import os,datetime

def exec_cmd(cmd):
  try:
    cmd_res=os.popen(cmd).read()
    return cmd_res.strip()
  except:
    return ''

# testlog when the script was executed
f=open('/flash/cron.log','w')
f.write(datetime.datetime.now().strftime('%d.%B %Y   %H:%M:%S')+'\n')
f.close()

# main
exec_cmd('interfaces 8/1/9 admin-state disable')

BTW, the file permissions of the script are set to 755.

Regards Holger
silvio
Alcatel Unleashed Certified Guru
Alcatel Unleashed Certified Guru
Posts: 1886
Joined: 01 Jul 2008 10:51
Location: Germany

Re: Issue with AOS command called from cronjob

Post by silvio »

Hi,
there are some hints in the switch management guides.
For executing a command there is written f.e.: os.system("show microcode") instead of exec_cmd. Maybe this is working too.

For using a cron-job to start a script you need to use the AMS.

Code: Select all

> appmgr start ams cron-app
> write memory flash-synchro
f.e.:

Code: Select all

> appmgr start ams cron-app argument "30 python3 /flash/python/XX.py , 60 python3 /flash/python/YY.py”
Every 30 minutes the script XX.py will be executed and every 60 min the other.

To stop and restart use:

Code: Select all

> appmgr stop ams cron-app
> appmgr restart ams cron-app
I hope that will be helpfull for you.
BR Silvio
HStr
Member
Posts: 8
Joined: 21 Apr 2022 05:20

Re: Issue with AOS command called from cronjob

Post by HStr »

Hi Silvio,

Thank you for your suggestions. I've already tried all of that. ALE support suggested the same. But the cronjob itself is not the issue. The script will be executed at the desired interval. All python commands except the system call (e.g. interfaces 8/1/9 admin-state disable) are executed. When I execute the python script manually from CLI the system call works as expected.

Regards Holger
silvio
Alcatel Unleashed Certified Guru
Alcatel Unleashed Certified Guru
Posts: 1886
Joined: 01 Jul 2008 10:51
Location: Germany

Re: Issue with AOS command called from cronjob

Post by silvio »

So I assume you know this link too: https://dokuwiki.alu4u.com/doku.php?id= ... on-cronjob

I think you need to force the support and present us the solution (if the support has anyone sometimes).
BR Silvio
HStr
Member
Posts: 8
Joined: 21 Apr 2022 05:20

Re: Issue with AOS command called from cronjob

Post by HStr »

Hi Silvio,

Yes I know this link. I try to force the support, although they probably don't understand the issue. As soon as there is a solution I will present it here.

Regards Holger
HStr
Member
Posts: 8
Joined: 21 Apr 2022 05:20

Re: Issue with AOS command called from cronjob

Post by HStr »

Hi,

As promised I provide the solution from ALE support:
After some investigation in lab, we figured that cron-app is executing the command in the "su" linux shell.
In order to disable the interface you can use this new script calling the "interfaces" module directly.
----------------------------------------------------
from subprocess import Popen, PIPE, STDOUT

process = Popen(['/vroot/bin/interfaces', 'port', '8/1/9','admin-state','disable'], stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate()
----------------------------------------------------
I also tried that with other commands in /vroot/bin (e.g. lanpower) and it works fine. :-)
The reason for my request is to check the status/reachability of PoE clients continuously and try to restart crashed devices by deactivate the link or switch off and on affected PoE ports to restart these devices.

BR Holger
silvio
Alcatel Unleashed Certified Guru
Alcatel Unleashed Certified Guru
Posts: 1886
Joined: 01 Jul 2008 10:51
Location: Germany

Re: Issue with AOS command called from cronjob

Post by silvio »

many thanks for sharing the solution.
best regards
Silvio
Post Reply

Return to “OmniSwitch 6560”