问题

问题

下面的几行是我添加到我的 Applesysdiagnose脚本副本中的:

  • 在任何已经编写了超时脚本的地方,它都是有效的
  • 我必须在两个区域添加超时,但我不知道该怎么做

在这两个领域,IFS=$'\n' ……

# If there exists a zfs binary, get some ZFS information
if [ -f "${ZFS}" ]
then
    #
    # The pool part
    #
    "${ECHO}" "Recording ZFS pool version information ..."
    "${ZPOOL}" upgrade &> ${data_directory_path}/"ZFS pools and properties.txt" &
    add_timeout_pid $! 30
    "${ECHO}" "    listing all ZFS pools ..."
    "${ECHO}" "" >> ${data_directory_path}/"ZFS pools and properties.txt"
    "${ECHO}" "ZFS pools:" >> ${data_directory_path}/"ZFS pools and properties.txt"
    "${ECHO}" "" >> ${data_directory_path}/"ZFS pools and properties.txt"
    "${ZPOOL}" list >> ${data_directory_path}/"ZFS pools and properties.txt" &
    add_timeout_pid $! 30
    "${ECHO}" "    all properties of each pool ..."
    OLD_IFS=$IFS
    IFS=$'\n'
    # If cut or zpool can not progress, then at this point: sysdiagnose will not progress  
    # <https://superuser.com/q/540939/84988>
    for zfspool in `"${ZPOOL}" list -H | cut -f 1`
    do
        { echo "\n*********************\n" ; "${ZPOOL}" get all "$zfspool" ; } >> ${data_directory_path}/"ZFS pools and properties.txt"
    done
    IFS=$OLD_IFS
    "${ECHO}" "    detailed health status and verbose data error information ..."
    "${ZPOOL}" status -v &> ${data_directory_path}/"ZFS pool detailed health status and verbose data error information.txt" &
    add_timeout_pid $! 30
    "${ECHO}" "    pools that are available but not currently imported"
    "${ZPOOL}" import &> ${data_directory_path}/"ZFS pools not imported.txt" &
    add_timeout_pid $! 30
    #
    # The file system part
    #
    "${ECHO}" "Recording ZFS file system version information ..."
    { "${ZFS}" upgrade ; "${ECHO}" "\n" ; } &> ${data_directory_path}/"ZFS file systems and properties.txt" &
    add_timeout_pid $! 30
    "${ECHO}" "    listing all ZFS file systems ..."
    #"${ECHO}" "ZFS file systems:" >> ${data_directory_path}/"ZFS file systems and properties.txt"
    "${ZFS}" list >> ${data_directory_path}/"ZFS file systems and properties.txt" &
    add_timeout_pid $! 30
    "${ECHO}" "    all properties of each file system"
    OLD_IFS=$IFS
    IFS=$'\n'
    # If cut or zfs can not progress, then at this point: sysdiagnose will not progress  
    # <https://superuser.com/q/540939/84988>
    for zfsfilesystem in `zfs list -H | cut -f 1`
    do
        { echo "\n*********************\n" ; "${ZFS}" get all "$zfsfilesystem" ; } >> ${data_directory_path}/"ZFS file systems and properties.txt"
    done
    IFS=$OLD_IFS
    #
    # Directory listings
    #
    "${ECHO}" "Listing the contents of /dev/dsk"
    { "${ECHO}" "Directory listing for /dev/dsk" ; echo "\n"; } >> ${data_directory_path}/"ZEVO-oriented directory listings.txt"
    { "${LS}" -@ael /dev/dsk ; echo "\n*********************\n" ; } >> ${data_directory_path}/"ZEVO-oriented directory listings.txt" &
    add_timeout_pid $! 30
    "${ECHO}" "Listing the contents of /var/zfs/dsk"
    { "${ECHO}" "Directory listing for /var/zfs/dsk" ; echo "\n" ; } >> ${data_directory_path}/"ZEVO-oriented directory listings.txt"
    "${LS}" -@ael /var/zfs/dsk >> ${data_directory_path}/"ZEVO-oriented directory listings.txt" &
    add_timeout_pid $! 30
fi

请注意评论:

# If cut or zpool can not progress, then at this point: sysdiagnose will not progress

问题

我怎样才能写入add_timeout_pid $! 30这两个区域?

背景

尽管我无法完整地重现该脚本(它不是开源的),但是 Lion 及更高版本的用户可能会发现 Apple 的脚本易于阅读:

/usr/bin/sysdiagnose

链接

sysdiagnose(1) OS X 手册页

cut(1) OS X 手册页

接受的答案在 shell 脚本中处理 ZFS 数据集名称中的空格

同样在超级用户中,强制运行 bash 脚本直至完成,但某些项目可能会卡住cut– 但答案是,对于具有以下功能的命令(例如、zfszpool) 没有任何好处没有超时选项

相关内容