Python Forum
OS command via python subprocess module
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
OS command via python subprocess module
#15
Thanks. Seems like now unzip is not working and hence chdir too.
It works only when dir /u03/21171382 and /u03/21463894 exist

#!/usr/local/bin/python3.6
import subprocess
from plumbum import local, cmd

patch = [21171382,21463894]

ORACLE_HOME = local.env['ORACLE_HOME']
path = local.env['PATH']
local.env['PATH'] = "{ohome}/bin:{ohome}/OPatch:{path}".format(ohome=ORACLE_HOME, path=local.env['PATH'])

osTyp = cmd.uname('-s').strip()

for i in patch:
    if osTyp == 'Linux':
        cmd.unzip('-o',"/u03/p{}_*.zip".format(i))
        local.cwd.chdir('/u03/{}'.format(i))
        subprocess.run('pwd', shell=True)

        #subprocess.run('opatch apply -silent', shell=True)
        print('Patch applied')

    elif osTyp == 'SunOs':
        cmd.unzip("p{}_121020_Solaris-x86-64.zip".format(i))
    else:
        print("!!\n!! unable to determine OS type !!\n!!")
Content of /u03:

[oracle@cdb1 u03]$ ls -ltr
total 97380
drwxr-xr-x. 3 oracle oinstall     4096 Jun 19  2017 app
-rwxrwx---. 1 oracle oinstall 99183505 Oct 17 20:57 p6880880_121010_Linux-x86-64.zip
-rwxrwx---. 1 oracle oinstall   451814 Oct 17 21:01 p21171382_12102180417_Generic.zip
-rwxrwx---. 1 oracle oinstall    73502 Oct 17 21:10 p21463894_121020_Linux-x86-64.zip
Error:
  File "/usr/local/lib/python3.6/site-packages/plumbum/path/local.py", line 354, in chdir
    os.chdir(str(newdir))
FileNotFoundError: [Errno 2] No such file or directory: '/u03/21171382'
Reply


Messages In This Thread
RE: OS command via python subprocess module - by alinaveed786 - Oct-20-2018, 04:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to pass a mongdb command to a module and execute it. cspower 0 423 Feb-03-2024, 09:54 PM
Last Post: cspower
  problem in using subprocess module akbarza 5 1,262 Sep-24-2023, 02:02 PM
Last Post: snippsat
  Using subprocess to execute complex command with many arguments medatib531 5 2,255 Apr-27-2023, 02:23 PM
Last Post: medatib531
  use subprocess on linux\pi wwith a "grep " command korenron 2 8,507 Oct-19-2021, 10:52 AM
Last Post: DeaD_EyE
  Question on subprocess module. knoxvilles_joker 3 2,828 Apr-11-2021, 12:51 AM
Last Post: knoxvilles_joker
  Error when running mktorrent subprocess command pythonnewbie138 4 4,133 Sep-16-2020, 01:55 AM
Last Post: pythonnewbie138
  Select correct item from list for subprocess command pythonnewbie138 6 3,514 Jul-24-2020, 09:09 PM
Last Post: pythonnewbie138
  python loop in subprocess vinothkumargomu 6 3,380 Jul-06-2020, 12:02 PM
Last Post: vinothkumargomu
  Subprocess command working for one cmd and for cmd one not wrking PythonBeginner_2020 0 4,213 Mar-25-2020, 01:52 PM
Last Post: PythonBeginner_2020
  How to parallel executing a command using subprocess? larkypython 0 2,231 Nov-28-2019, 03:49 PM
Last Post: larkypython

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020