Results 1 to 8 of 8

Thread: [SOLVED] Zenity w/ IF statement to check if selected directory is not EXT3

  1. #1
    Join Date
    Oct 2007
    Beans
    832
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    [SOLVED] Zenity w/ IF statement to check if selected directory is not EXT3

    Hi everyone,

    I need some help with checking whether or not a directory is EXT3 or not.

    Code:
    #!/bin/bash
    
    zenity --directory --file-selection
    This brings up Zenity where I can click on a drive.

    I would like the output (drive/location selected) to be checked to see if it's a file system that is compatible with accepting permissions (EXT3, etc...) If it's not compatible (ex: FAT32 or NTFS) then I want to loop back.

    I can't find anything that I can use to put in an IF/WHILE statement for checking file system type, so I can loop if it's FAT32 or NTFS.

    Does anyone know how to do this?

    thanks.

    P.S. One last thought. Is it possible to make the above Zenity code open in a specific folder and not allow me to change it?

    thanks again...
    Last edited by mdpalow; December 19th, 2007 at 07:37 PM.

  2. #2
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Zenity w/ IF statement to check if selected directory is not EXT3

    Something like this perhaps?

    Code:
    dir=$(zenity --file-selection --directory)
    
    while [ $(stat --file-system -c "%T" "$dir") != ext2/ext3 ]; do
      zenity --error --text="Directory must be in an ext2 or ext3 filesystem"
      dir=$(zenity --file-selection --directory)
    done
    
    echo "Ok, $dir is fine"
    And I don't think you can force a directory in zenity like that. I guess the closest thing would be to make the list of legal files and put it in a "zenity --list"

    EDIT: Oh, mdpallow, hello again
    Last edited by geirha; December 19th, 2007 at 10:44 PM.

  3. #3
    Join Date
    Oct 2007
    Beans
    832
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Zenity w/ IF statement to check if selected directory is not EXT3

    lol

    thank you geirha!

    Sorry to take so long to reply, but I was away for a while and then needed to have someone test it for me to see if they got the same problem I did.

    Basically, the script works perfectly against my usb flash drive, but when I tested it against my usb hard drive that is ntfs partitioned, I get:

    [: too many arguments

    in the " while [ $(stat --file-system -c "%T" "$dir") != ext2/ext3 ]; do "

    When selecting the NTFS partition (USB Hard Drive), It says it's ok and moves forward. I would think it shouldn't do that.

    Can you think of anything? A friend is getting the same error.

    Thanks...
    Last edited by mdpalow; December 20th, 2007 at 02:52 AM.

  4. #4
    Join Date
    Oct 2007
    Beans
    832
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Zenity w/ IF statement to check if selected directory is not EXT3

    do you think it allowed because of ntfs-3g , which allows writing to NTFS?

  5. #5
    Join Date
    Oct 2007
    Beans
    832
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Zenity w/ IF statement to check if selected directory is not EXT3

    seems to be another small problem.

    Once you enter the loop (after selecting a fat file system) and then click CANCEL, you get:

    stat: cannot read file system information for `': No such file or directory
    /home/me/Desktop/new file: line 13: [: !=: unary operator expected
    Ok, is fine

    line 13 is the WHILE line...

  6. #6
    Join Date
    Oct 2007
    Beans
    832
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Zenity w/ IF statement to check if selected directory is not EXT3

    bumpidibump...

    Is there anyone else on-line who might be able to help??

  7. #7
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Zenity w/ IF statement to check if selected directory is not EXT3

    The NTFS one probably has spaces in it, so we'll need to enclose that stat command in quotes. And checking if zenity failed is of course a good idea too, so:

    Code:
    dir=$(zenity --file-selection --directory)
    if [ $? != 0 ]; then
      echo "ok, bye bye"
      exit 1
    fi
    
    while [ "$(stat --file-system -c "%T" "$dir")" != "ext2/ext3" ]; do
      zenity --error --text="Directory must be in an ext2 or ext3 filesystem"
      dir=$(zenity --file-selection --directory)
      if [ $? != 0 ]; then
        echo "ok, bye bye"
        exit 1
      fi
    done
    
    echo "Ok, $dir is fine"

  8. #8
    Join Date
    Oct 2007
    Beans
    832
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Zenity w/ IF statement to check if selected directory is not EXT3

    Thank you very much Geirha

    That worked.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •