我目前正在编写一个小脚本来备份大量软盘,然后将它们格式化以备后用。
我dd
用来复制磁盘的映像并复制磁盘上的cp
所有文件。
以下是我用来执行此操作的命令:
# Copying disk image
dd if="/dev/fd0" of="/path/to/backup/folder" &>/dev/null && sync
# Copying disk files
cp -R "/mnt/floppy/." "/path/to/backup/folder/" &>/dev/null
Run Code Online (Sandbox Code Playgroud)
在这个过程之后,脚本需要格式化软盘。我的问题是我希望我的脚本只有在两个备份命令 (dd
和cp
) 都成功时才能格式化软盘。
例如,如果dd
因为坏块而无法复制所有1.44MB 的软盘,则不要格式化软盘。
如何测试两个命令是否成功(它们必须单独测试,因为我并不总是同时备份磁盘的映像和文件)?
我必须异步运行一堆 bash 命令,一旦完成,我需要根据其退出代码和输出执行操作。请注意,我无法预测这些任务在我的实际用例中将运行多长时间。
为了解决这个问题,我最终使用了以下算法:
For each task to be run:
Run the task asynchronously;
Append the task to the list of running tasks.
End For.
While there still are tasks in the list of running tasks:
For each task in the list of running tasks:
If the task has ended:
Retrieve the task's exit code and output;
Remove the task from the list of running tasks.
End If.
End For
End While.
Run Code Online (Sandbox Code Playgroud)
这给了我以下 bash 脚本:
For each task to be …
Run Code Online (Sandbox Code Playgroud) 我试图掌握 APT 固定在 Debian 下的工作原理,但我很难理解它如何解决优先级问题。
我有一个source.list
文件,其中按此确切顺序包含以下条目:
deb <repository> stretch main
deb <repository> testing main
deb <repository> unstable main
Run Code Online (Sandbox Code Playgroud)
以下存储库包含每个分支的这些包:
dependency version 1.0
;dependency version 2.0
;program
和dependency version 2.0
;包program
取决于dependency version 2.0
.
我需要安装包program
,但我想安装尽可能少的包unstable
,所以我创建了以下preferences
文件来固定这个分支:
Package: *
Pin: release a=unstable
Pin-Priority: -1
Run Code Online (Sandbox Code Playgroud)
如果我正确理解它是如何工作的,它应该unstable
只在我明确告诉 APT 时安装软件包。
我还创建了一个apt.conf
文件来确保stable
分支是默认的:
APT::Default-Release "stable";
Run Code Online (Sandbox Code Playgroud)
运行命令后apt-get update
,分支应具有以下优先级:
stable: 990
testing: 500
unstable: …
Run Code Online (Sandbox Code Playgroud)