ทำให้“ apt-get update” แสดงผลลัพธ์ที่แน่นอนว่า `apt update '


8

ฉันกำลังเรียนรู้ส่วนต่อประสาน CLI ของเครื่องมือบรรจุภัณฑ์ขั้นสูง จากการส่งออกของapt(8)เมื่อ stdout ของมันไม่ได้ขั้วมันไม่เหมาะสำหรับ "สคริปต์คาดหวังว่าอินเตอร์เฟซการเขียนโปรแกรมที่มีเสถียรภาพ" apt-get(8)ดังนั้นฉันการดูที่

ข้อแตกต่างอย่างหนึ่งระหว่างapt updateและapt-get updateคือข้อหลังไม่มีบรรทัดสุดท้ายหลังจากแคชทั้งหมดได้รับการอัพเดต:

8 packages can be upgraded. Run 'apt list --upgradable' to see them.

ฉันต้องการทราบว่าฉันจะแสดงบรรทัดที่แน่นอนนี้ได้apt-get(8)อย่างไร


เท่าที่ฉันรู้apt(Advanced Packaging Tool) และapt-getสิ่งต่าง ๆ พวกเขาออกแบบมาเพื่อทำงานแตกต่างจากสิ่งที่ฉันเข้าใจ หากมีสิ่งที่คุณต้องการคุณอาจสร้างนิสัยให้ใช้คำสั่งนั้นแทน
Wynter

คำตอบ:


9

man apt-get แสดงให้เห็นว่า:

   -s, --simulate, --just-print, --dry-run, --recon, --no-act
       No action; perform a simulation of events that would occur based on
       the current system state but do not actually change the system.
       Locking will be disabled (Debug::NoLocking) so the system state
       could change while apt-get is running. Simulations can also be
       executed by non-root users which might not have read access to all
       apt configuration distorting the simulation. A notice expressing
       this warning is also shown by default for non-root users
       (APT::Get::Show-User-Simulation-Note). Configuration Item:
       APT::Get::Simulate.

ดังนั้นถ้าคุณทำ:

apt-get upgrade --dry-run

มันจะเอาท์พุท:

...
4 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
...

ใช่ฉันเดินผ่านman 8 apt-getและพบว่าตัวเลือก aptแต่ผลลัพธ์แตกต่างจาก
iBug

แตกต่างกันอย่างไร ฉันเพิ่งตรวจสอบระบบของฉันและมันเหมือนกัน ฉันคิดว่ามันเหมือนกันเพราะaptมันเป็นโปรแกรมห่อหุ้มโปรแกรมapt-getและนั่นคือเหตุผลที่คำเตือนมีอยู่
tu-Reinstate Monica-dor duh

aptแสดงให้เห็น8 packages can be upgraded. Run 'apt list --upgradable' to see them.ในขณะที่คำตอบของคุณแสดงให้เห็น4 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
iBug

1
ใช่นั่นเป็นเพราะคุณมี 8 ที่จะอัพเกรดที่ฉันมี 4 หรือคุณกำลังอ้างถึงข้อความที่แตกต่างกัน?
tu-Reinstate Monica-dor duh

4
ใช่ว่าเป็นว่าสิ่งที่เตือนเป็นเรื่องเกี่ยวกับ aptจะไม่รับประกันข้อความนั้นและอาจไม่รับประกันหมายเลขนั้น apt-getอย่างไรก็ตามมีข้อกำหนดที่เข้มงวดเนื่องจากซอฟต์แวร์อื่น ๆ (เช่น UIs และ daemons) ใช้เพื่อประมวลผลในรูปแบบต่างๆ ดังนั้นคุณสามารถเปลี่ยนรหัสของคุณเพื่อรับapt-getผลลัพธ์หรือ| sed 's/to upgrade/packages can be upgraded/g'ตัวอย่างเช่น (และเสี่ยงต่อการแตกรหัสของคุณในภายหลัง)
tu-Reinstate Monica-dor duh

4

การคาดเดาว่าคุณต้องจัดการกับจำนวนการอัปเดตที่มีอยู่นี่เป็นคำแนะนำ:

# With no option, returns two numbers, no CR nor LF
/usr/lib/update-notifier/apt-check

# With --human-readable, returns numbers, locale LANG text & CR/LF
/usr/lib/update-notifier/apt-check  --human-readable

ไม่จำเป็นต้อง sudo
เอาต์พุตใช้งานง่าย

ตัวเลือกเพิ่มเติม:

> /usr/lib/update-notifier/apt-check  --help
Usage: apt-check [options]

Options:
  -h, --help            show this help message and exit
  -p, --package-names   Show the packages that are going to be
                        installed/upgraded
  --human-readable      Show human readable output on stdout
  --security-updates-unattended
                        Return the time in days when security updates are
                        installed unattended (0 means disabled)

นี่เป็นสิ่งที่แน่นอนที่ใช้ในการสร้างmotdในการเข้าสู่ระบบ SSH?
iBug

ใช่มันดูเหมือนเอาท์พุทเดียวกัน แต่ฉันไม่รู้วิธี motd
cmak.fr

2

จากman 8 apt:

... เปิดใช้งานตัวเลือกบางอย่าง ...

จากนั้นฉันก็ผ่าน/usr/share/doc/apt/examples/configure-index.gz(ใช้zcat(1)เพื่อแสดงเนื้อหาข้อความ) และสังเกตเห็นตัวเลือกนี้:

apt::cmd::show-update-stats

ดังนั้นฉันจึงทำตามคำสั่งต่อไปนี้ว่าทำสิ่งที่ฉันต้องการ:

# apt-get -o apt::cmd::show-update-stats=true update

ผ่านการทดสอบแล้วว่าทำงานบน Xenial และ Bionic

โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.