Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In the lines below, which I added to my copy of Apple's sysdiagnose script:

  • wherever a timeout is already scripted, it is effective
  • I must add timeouts in two areas, but I don't know how to do so.

In the two areas, 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  
    # <http://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  
    # <http://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

Note the comment:

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

Question

How can I write add_timeout_pid $! 30 into those two areas?

Background

Whilst I can't reproduce the script in its entirety (it's not open source), users of Lion and greater may find Apple's script human-readable:

/usr/bin/sysdiagnose

Links

sysdiagnose(1) OS X Manual Page

cut(1) OS X Manual Page

The accepted answer to Handling whitespaces in the name of a ZFS dataset in a shell script

Also in Super User, Force a bash script to run to completion where some items may stick – but the answer there is no good for commands (such as cut, zfs and zpool) that have no timeout option.

share|improve this question
    
The timeout features requires you to run things in a subshell in the background, see the other uses of that function in the existing script. The results are then only collected after timeout is called, all data gathering processes redirect their output somewhere. Just wrap all your ZFS diagnosis in a subshell, and timeout that process, similar to "Gather simple diskutil list". –  Daniel Beck Jan 24 '13 at 7:02
    
@DanielBeck I'm looking now but can't see what you mean – sorry. I'm easily confused with scripts, and generally a bit dyslexic about learning things … I need some hand-holding here to avoid learning the wrong lessons … –  Graham Perrin Jan 24 '13 at 7:07
    
All occurrences of add_timeout_pid in the original script immediately follow commands executed in the background using the & at the end (e.g. line 544-545, 688-689). Only in line 768 will the entire script wait for all of these to complete. Your use case, with multiple commands etc. is covered by what happens in a sub-shell (see the bash docs on "Compound Commands") with diskutil in lines 502-512. Try to understand how this works, and follow those rules with your new sub-script (e.g. not running the timeout function after every command). Line numbers from 10.8.2 used. –  Daniel Beck Jan 24 '13 at 17:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.