Terminal Output to use for IF Check

Discussion in 'Mac Programming' started by jdshub, Jul 21, 2014.

  1. jdshub macrumors newbie

    Joined:
    Jul 21, 2014
    #1
    Hi,

    basically I need to get a output of fdesetup status in order to check the variable and use it for a if check.

    Basically I want to do the following:

    Code:
    ## Check for FileVault 2 Status
    
    fdesetup status
    ## Needs to get an output "deferred for user xxx"
    ## Exact output: FileVault is Off. Deferred enablement appears to be active for user 'xxx'.
    
    if (fdesetup status = deferred) then
     #logout user
    osascript -e 'tell application "loginwindow" to  «event aevtrlgo»'
    exit 0
    fi
    
    
    Somehow I am stuck with this in my brain :/ sorry!

    Best regards,
    Dan :apple::apple:
     
  2. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #2
    Hi Dan,

    You probably want something along the lines of:


    Code:
    if [ "`fdesetup status`" = "FileVault is Off." ]; then
    	echo "Do stuff..."
    fi
    
    ...I'm no shell scripting ninja so others may have better solutions.

    Good luck!
     
  3. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #3
    Code:
    EXIT STATUS
         The exit status of the tool is set to indicate whether any error was detected. The values returned are:
    
         0                  No error, or successful operation.
    
         1                  FileVault is Off.
    
         2                  FileVault appears to be On but Busy.
    
         11                 Authentication error.
    
         12                 Parameter error.
    
         13                 Unknown command error.
    
         14                 Bad command error.
    
         15                 Bad input error.
    
         16                 Legacy FileVault error.
    
         17                 Added users failed error.
    
         18                 Unexpected keychain found error.
    
         19                 Keychain error. This usually means the FileVaultMaster keychain could not be moved
                            or replaced.
    
         20                 Deferred configuration setup missing or error.
    
         21                 Enable failed (Keychain) error.
    
         22                 Enable failed (CoreStorage) error.
    
         23                 Enable failed (DiskManager) error.
    
         24                 Already enabled error.
    
         25                 Unable to remove user.
    
         26                 Unable to change recovery key.
    
         27                 Unable to remove recovery key.
    
         28                 FileVault is either off, busy, or the volume is locked.
    
         99                 Internal error.
    
    It looks like you need to see if the exit code is 1.

    From this post:
    https://discussions.apple.com/message/20213829

    Code:
    set exitCode to do shell script "fdsetup status; echo $?"
    
    Then you can just check against 1, or any other exit code. This feels more precise than parsing human-readable output.

    -Lee
     
  4. jdshub, Jul 21, 2014
    Last edited: Jul 22, 2014

    jdshub thread starter macrumors newbie

    Joined:
    Jul 21, 2014
    #4
    Hi Lee,

    many thanks for your information.

    My status code is:

    Code:
    XXX:~ dan$ fdesetup status
    FileVault is Off.
    Deferred enablement appears to be active for user 'dan'.
    XXX:~ dan$ set exitCode to do shell script "fdsetup status; echo $?"
    XXX:~ dan$ echo $?
    0
    XXX:~ dan$
    
    I checked with another output code:

    Code:
    XXX:~ dan$ sudo fdesetup disable
    Password:
    Enter a password for '/', or the recovery key:
    FileVault has been disabled.
    XXX:~ dan
    $ fdesetup status
    FileVault is Off.
    Decryption in progress: Percent completed = 99.25
    XXX:~ dan$ set exitCode to do shell script "fdsetup status; echo $?"
    XXX:~ dan$ echo $?
    0
    
    And another scenario:

    Code:
    XXX:~ dan $ fdesetup status
    FileVault is On.
    Encryption in progress: Percent completed = 0.19
    XXX:~ dan $ set exitCode to do shell script "fdsetup status; echo $?"
    XXX:~ dan $ echo $?
    0
    
    Do you have another clue?
    That leads me to think, that we need to human readable output?

    Best regards,
    Dan
     
  5. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #5
    Sorry, thought this was AppleScript. Just print $? after running fdsetup status.

    -Lee
     
  6. jdshub thread starter macrumors newbie

    Joined:
    Jul 21, 2014
    #6
    Hi Lee,

    thanks a lot...I did it with a grep and checked it the output matches the grep.
    Works like a charm :D

    Best regards,
    Dan
     

Share This Page