如何通过Shell脚本退出超级用户?

时间:2018-01-19 06:49:03

标签: shell unix scripting

我在Unix中以超级用户身份登录,我需要编写一个脚本来更改root用户的目录权限,而无需退出超级用户。当我执行这个脚本时,流程突然停止,它不会继续前进。下面是我正在使用的脚本。

private void generateQuotationOrderReport(final Object internalOdooQuoteId) throws XmlRpcException, IOException {
logger.info("generating quote report pdf for order #: " + internalOdooQuoteId);
final Object internalOdooQuoteIds = asList((Object[]) models.execute("execute_kw", asList(
  db, uid, password,
  "sale.order", "search",
  asList(asList(
    asList("id", "=", internalOdooQuoteId)
  )),
  new HashMap() {{
    put("limit", 1);
  }}
)));

final XmlRpcClientConfigImpl report_config = new XmlRpcClientConfigImpl();
report_config.setServerURL(
  new URL(String.format("%s/xmlrpc/2/report", url)));
final Map<String, Object> result = (Map<String, Object>)models.execute(
  report_config, "render_report", asList(
    db, uid, password,
    "sale.report_saleorder",
    internalOdooQuoteIds));
final byte[] report_data = DatatypeConverter.parseBase64Binary(
  (String)result.get("result"));

File file = new File("records/quotation_order.pdf");
FileUtils.writeByteArrayToFile(file, report_data);
}

提前致谢

1 个答案:

答案 0 :(得分:2)

shell脚本不是要发送到shell的击键列表。这是一个由shell执行的程序。因此,由于脚本的第一行是exit,所以shell将要做的第一件事是退出,并且脚本中没有其他内容可以执行,因为shell不再运行。

我不清楚你希望你的脚本做什么,但是为了让它有机会工作,你肯定需要消除exit语句。您对sudo的呼叫也不会像您预期的那样有效。如果您需要以另一个用户身份执行命令,则应使用sudo命令,如下所示:

sudo -u other_username command_to_run

因此,如果要将某些文件复制为名为super的用户,则调用将为:

sudo -u super cp *csv /export/home/user1/RPT_GEN

希望这有帮助。