From owner-freebsd-questions@FreeBSD.ORG Tue Aug 26 14:42:45 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C072B16A4BF for ; Tue, 26 Aug 2003 14:42:45 -0700 (PDT) Received: from webserver.get-linux.org (adsl-64-161-78-226.dsl.lsan03.pacbell.net [64.161.78.226]) by mx1.FreeBSD.org (Postfix) with SMTP id DDE4443FA3 for ; Tue, 26 Aug 2003 14:42:44 -0700 (PDT) (envelope-from oremanj@webserver.get-linux.org) Received: (qmail 5669 invoked by uid 1000); 26 Aug 2003 21:44:42 -0000 Date: Tue, 26 Aug 2003 14:44:42 -0700 From: Joshua Oreman To: Charles Howse Message-ID: <20030826214442.GA3912@webserver> References: <20030826160456.GD11087@webserver> <002a01c36c0c$af801500$04fea8c0@moe> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <002a01c36c0c$af801500$04fea8c0@moe> User-Agent: Mutt/1.4.1i cc: questions@freebsd.org Subject: Re: Detect floppy diskette X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Aug 2003 21:42:45 -0000 On Tue, Aug 26, 2003 at 03:00:23PM -0500 or thereabouts, Charles Howse wrote: > > Try this: > > % perl > > use POSIX qw/:fcntl_h dup2 setsid/; > > if (fork) { exit; } > > setsid; > > > > my $fd = POSIX::open "/dev/null", O_WRONLY or die "Can't open > > /dev/null: $!\n"; > > dup2 $fd, 0; > > dup2 $fd, 1; > > dup2 $fd, 2; > > > > sleep 5; > > > > system "sudo mount /dev/fd0 /mnt"; > > > > % # wait for an error within 5 seconds or so > > > > If no error appears, I think you forgot the / on /dev/null up > > there :-) Make > > sure to unmount the floppy afterwards. > > If there is an error, it proves that it was/is a kernel message. > > Looks good, now...I have to insert this perl code into a bash script as > a function. > This generates a syntax error: > #!/usr/local/bin/bash > > Chkflp(){ > /usr/bin/perl add < use POSIX qw/:fcntl_h dup2 setsid/; > if (fork) { exit; } > setsid; > > my $fd = POSIX::open "/dev/null", O_WRONLY or die "Can't open > /dev/null: $!\n"; > dup2 $fd, 0; > dup2 $fd, 1; > dup2 $fd, 2; > > sleep 5; put EOF on a new line here > } > But I think you misunderstood me. This script will check to see whether you *can* trap the error. Run it manually on the command line, wait a few seconds, see if you get an error w/o a floppy in the drive. If no error, great; put this in bash script: FloppyInDrive() { perl << 'EOF' use POSIX; my $fd = POSIX::open "/dev/null", POSIX::O_WRONLY or die "can't open /dev/null"; dup2 $fd, $_ for (0, 1, 2); exec "dd if=/dev/fd0 of=/dev/null bs=1k count=1"; EOF return $? } until FloppyInDrive; do echo "please insert floppy and press enter"; read key; done -- Something like that. This is how it looks on my Linux box (sorry, no FreeBSD example yet): bash-2.05a# FloppyInDrive() { > perl << 'EOF' > use POSIX; > my $fd = POSIX::open "/dev/null", POSIX::O_WRONLY or die "can't open /dev/null"; > dup2 $fd, $_ for (0, 1, 2); > exec "dd if=/dev/floppy/0 of=/dev/null bs=1k count=1"; > EOF > return $? > } bash-2.05a# bash-2.05a# until FloppyInDrive; do echo "please insert floppy and press enter"; read key; done bash-2.05a# SysRq : Changing Loglevel Loglevel set to 9 until FloppyInDrive; do echo "please insert floppy and press enter"; read key; done end_request: I/O error, dev 02:00 (floppy), sector 0 please insert floppy and press enter end_request: I/O error, dev 02:00 (floppy), sector 0 please insert floppy and press enter bash-2.05a# SysRq : Changing Loglevel Loglevel set to 3 until FloppyInDrive; do echo "please insert floppy and press enter"; read key; done please insert floppy and press enter please insert floppy and press enter bash-2.05a# If the original errors, well, maybe the above will work anyway. Maybe it won't. Oh well. -- Josh > > > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"