Need unattended way to run sosreport. sysreport could be run as "echo y | sysreport" to require no further prompting. It would you useful for sosreport to provide something similar (maybe just command line options for confirmation, name and case number).
*** Bug 429405 has been marked as a duplicate of this bug. ***
Attached are 2 patches which implement this functionality through the commandline options --name and --ticket-number. Both of these options must be present for an unattended execution to occur. sosreport: --- /usr/sbin/sosreport 2008-03-28 10:28:49.000000000 -0400 +++ /usr/sbin/sosreport2 2008-07-03 00:46:25.000000000 -0400 @@ -142,6 +142,12 @@ __cmdParser__.add_option("--no-multithread", action="store_true", \ dest="nomultithread", \ help="disable multi-threaded gathering mode (slower)", default=False) +__cmdParser__.add_option("--name", action="extend", \ + dest="name",type="string", \ + help="first initial and last name.") +__cmdParser__.add_option("--ticket-number", action="extend", \ + dest="ticketnumber", type="string", \ + help="ticket number.") if sys.argv[0].endswith("sysreport"): try: @@ -538,9 +544,12 @@ if not len(loadedplugins): soslog.error(_("no valid plugins were enabled")) sys.exit(1) - - try: - raw_input(_("""This utility will collect some detailed information about the + + isUnattended = False + if len(__cmdLineOpts__.name) > 0 and len(__cmdLineOpts__.ticketnumber) > 0: isUnattended = True + if not isUnattended: + try: + raw_input(_("""This utility will collect some detailed information about the hardware and setup of your Red Hat Enterprise Linux system. The information is collected and an archive is packaged under /tmp, which you can send to a support representative. @@ -552,9 +561,9 @@ Press ENTER to continue, or CTRL-C to quit. """)) - except KeyboardInterrupt: - print - sys.exit(0) + except KeyboardInterrupt: + print + sys.exit(0) # Call the diagnose() method for each plugin tmpcount = 0 @@ -583,7 +592,10 @@ print try: while True: - yorno = raw_input( _("Are you sure you would like to continue (y/n) ? ") ) + if not isUnattended: + yorno = raw_input( _("Are you sure you would like to continue (y/n) ? ") ) + else: + yorno = _("Y") if yorno == _("y") or yorno == _("Y"): print break @@ -594,7 +606,7 @@ print sys.exit(0) - policy.preWork() + policy.preWork(__cmdLineOpts__.name, __cmdLineOpts__.ticketnumber) # Call the setup() method for each plugin for plugname, plug in loadedplugins: ================= policyredhat.py: --- /usr/lib/python2.4/site-packages/sos/policyredhat.py 2008-07-03 00:36:27.000000000 -0400 +++ /usr/lib/python2.4/site-packages/sos/policyredhat.py2 2008-07-03 00:35:32.000000000 -0400 @@ -121,19 +121,25 @@ name = "-".join(fields[:-3]) return (name, version, release, arch) - def preWork(self): + def preWork(self, name="", ticket=""): # this method will be called before the gathering begins localname = commands.getoutput("/bin/uname -n").split(".")[0] try: - self.reportName = raw_input(_("Please enter your first initial and last name [%s]: ") % localname) - self.reportName = re.sub(r"[^a-zA-Z.0-9]", "", self.reportName) + if len(name) == 0: + self.reportName = raw_input(_("Please enter your first initial and last name [%s]: ") % localname) + else: + self.reportName = str(name) + self.reportName = re.sub(r"[^a-zA-Z.0-9]", "", self.reportName) if len(self.reportName) == 0: self.reportName = localname - self.ticketNumber = raw_input(_("Please enter the case number that you are generating this report for: ")) - self.ticketNumber = re.sub(r"[^0-9]", "", self.ticketNumber) + if len(ticket) == 0: + self.ticketNumber = raw_input(_("Please enter the case number that you are generating this report for: ")) + else: + self.ticketNumber = str(ticket) + self.ticketNumber = re.sub(r"[^0-9]", "", self.ticketNumber) print except KeyboardInterrupt: print
Created attachment 310878 [details] Updated prework() to accept optional @name and @ticketnumber values for unattended execution.
Created attachment 310879 [details] Updates sosreport with the --name and --ticket-number options for unattended execution.
Revised sosreport patch: - Storing values properly now --- /usr/sbin/sosreport 2008-03-28 10:28:49.000000000 -0400 +++ /usr/sbin/sosreport2 2008-07-03 01:09:10.000000000 -0400 @@ -142,6 +142,12 @@ __cmdParser__.add_option("--no-multithread", action="store_true", \ dest="nomultithread", \ help="disable multi-threaded gathering mode (slower)", default=False) +__cmdParser__.add_option("--name", action="store", \ + dest="name",type="string", \ + help="first initial and last name.", default="") +__cmdParser__.add_option("--ticket-number", action="store", \ + dest="ticketnumber", type="string", \ + help="ticket number.", default="") if sys.argv[0].endswith("sysreport"): try: @@ -538,9 +544,12 @@ if not len(loadedplugins): soslog.error(_("no valid plugins were enabled")) sys.exit(1) - - try: - raw_input(_("""This utility will collect some detailed information about the + + isUnattended = False + if len(__cmdLineOpts__.name) > 0 and len(__cmdLineOpts__.ticketnumber) > 0: isUnattended = True + if not isUnattended: + try: + raw_input(_("""This utility will collect some detailed information about the hardware and setup of your Red Hat Enterprise Linux system. The information is collected and an archive is packaged under /tmp, which you can send to a support representative. @@ -552,9 +561,9 @@ Press ENTER to continue, or CTRL-C to quit. """)) - except KeyboardInterrupt: - print - sys.exit(0) + except KeyboardInterrupt: + print + sys.exit(0) # Call the diagnose() method for each plugin tmpcount = 0 @@ -583,7 +592,10 @@ print try: while True: - yorno = raw_input( _("Are you sure you would like to continue (y/n) ? ") ) + if not isUnattended: + yorno = raw_input( _("Are you sure you would like to continue (y/n) ? ") ) + else: + yorno = _("Y") if yorno == _("y") or yorno == _("Y"): print break @@ -594,7 +606,10 @@ print sys.exit(0) - policy.preWork() + if isUnattended: + policy.preWork(__cmdLineOpts__.name, __cmdLineOpts__.ticketnumber) + else: + policy.preWork() # Call the setup() method for each plugin for plugname, plug in loadedplugins:
Created attachment 310880 [details] Properly sets default empty values for --name and --ticket-number. - Properly sets default empty values for --name and --ticket-number. - Only attempts to pass the values to preWork() for unattended execution if they are both present.
Created attachment 310881 [details] Properly sets default empty values for --name and --ticket-number.
This request was evaluated by Red Hat Product Management for inclusion in a Red Hat Enterprise Linux maintenance release. Product Management has requested further review of this request by Red Hat Engineering, for potential inclusion in a Red Hat Enterprise Linux Update release for currently deployed products. This request is not yet committed for inclusion in an Update release.
rhel5 changeset for this patch : https://fedorahosted.org/sos/changeset/508/branches/RHEL-5
Created attachment 315268 [details] adds --name and --ticket-number to the man page.
An advisory has been issued which should help the problem described in this bug report. This report is therefore being closed with a resolution of ERRATA. For more information on therefore solution and/or where to find the updated files, please follow the link below. You may reopen this bug report if the solution does not work for you. http://rhn.redhat.com/errata/RHBA-2009-0171.html