AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 571122
Accepted
Cerin
Cerin
Asked: 2015-01-08 14:37:03 +0800 CST2015-01-08 14:37:03 +0800 CST 2015-01-08 14:37:03 +0800 CST

如何在运行命令后自动重启

  • 772

我在一堆机器上安装更新,我只想运行:

sudo apt-get update
sudo apt-get upgrade
sudo reboot

一次在所有机器上(当然是几个小时后)让它们运行而不需要我输入密码。但是,上面的命令不起作用,因为它们都需要root权限,因此每次都需要我的密码。在单个sudo连接下运行它们&&似乎不起作用。此外,如果更新有发行说明,它会显示所有发行说明并暂停,直到我退出less。

我该如何做到这一点?

updates
  • 3 3 个回答
  • 2718 Views

3 个回答

  • Voted
  1. Best Answer
    psusi
    2015-01-08T16:18:43+08:002015-01-08T16:18:43+08:00

    sudo -s将提示您输入一次密码,然后让您坐在一个根 shell 中,该 shell 一直保留到您exit. 在那里你可以链接命令,如apt-get update && apt-get upgrade -y && reboot.

    • 5
  2. Xen2050
    2015-01-08T15:33:29+08:002015-01-08T15:33:29+08:00

    所以您不希望您的用户必须输入密码才能使用 sudo?您可以将这样的行添加到/etc/sudoers或文件中/etc/sudoers.d/

      username  ALL=(ALL) NOPASSWD: ALL
      

      或者只允许一些程序,例如rebootand apt-get:

      username ALL=(ALL) NOPASSWD: /sbin/reboot, /usr/bin/apt-get
      

    可能也想研究一些apt-get选项,例如:

         -q, --quiet
             Quiet; produces output suitable for logging, omitting progress
             indicators. More q's will produce more quiet up to a maximum of 2.
             You can also use -q=# to set the quiet level, overriding the
             configuration file. Note that quiet level 2 implies -y; you should
             never use -qq without a no-action modifier such as -d, --print-uris
             or -s as APT may decide to do something you did not expect.
             Configuration Item: quiet.
      
         -y, --yes, --assume-yes
             Automatic yes to prompts; assume "yes" as answer to all prompts and
             run non-interactively. If an undesirable situation, such as
             changing a held package, trying to install a unauthenticated
             package or removing an essential package occurs then apt-get will
             abort. Configuration Item: APT::Get::Assume-Yes.
      
         --force-yes
             Force yes; this is a dangerous option that will cause apt to
             continue without prompting if it is doing something potentially
             harmful. It should not be used except in very special situations.
             Using force-yes can potentially destroy your system! Configuration
             Item: APT::Get::force-yes.
      

    或者你可以盲目地输入一些换行符或“q” apt-get,我曾经安装一个包,它会忽略apt选项,比如-y等待按键(可能在它的 preinst 或 postinst 脚本中)。可以尝试类似的东西:

      {
      sleep 20
      echo
      echo "q"
      } | apt-get upgrade
      


    如果你在每台机器上安装完全相同的包,你不需要update和upgrade每个人都通过互联网,你可以.deb一次下载所有需要的文件:

      sudo apt-get install --download-only [packages]
      

      或者

      sudo apt-get upgrade --download-only
      

    然后从本地/​​共享文件夹安装它们

      sudo dpkg -iR /folder_of_debs
      

    • 3
  3. protld
    2016-06-22T10:43:07+08:002016-06-22T10:43:07+08:00

    如果你是“root”,最简单的解决方案是

    apt-get -y update && apt-get -y upgrade && reboot
    

    如果您是系统上的用户,首先确保在 sudoers 中启用了该用户,然后键入:

    sudo apt-get -y update && apt-get -y upgrade && reboot
    
    • 0

相关问题

  • 无法更新雷鸟

  • 如何从命令行仅安装安全更新?关于如何管理更新的一些提示

  • iPod Touch (iPhone) 的固件更新?

  • 如何让 Ubuntu 减少检查更新的频率?对于 11.04 及更高版本对于赶时间的人!通过 Ubuntu 软件中心

  • 如何启用自动更新?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve