Detect floppy diskette
Hi, Using bash, how can I silently check to see whether there is a floppy diskette in the drive? When I do: # mount /dev/fd0 /mnt dev/null 21 I still get an error msg on screen. Thanks, Charles ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Detect floppy diskette
On Tue, Aug 26, 2003 at 08:17:35AM -0500 or thereabouts, Charles Howse wrote: Hi, Using bash, how can I silently check to see whether there is a floppy diskette in the drive? When I do: # mount /dev/fd0 /mnt dev/null 21 I still get an error msg on screen. Probably the message is generated by the kernel and cannot be ignored. 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. -- Josh Thanks, Charles ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
RE: Detect floppy diskette
Try this: #!/usr/bin/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; Maybe I'm doing something wrong, all this script does is run and exit with status 0, whether I have a diskette in the drive or not. No output to screen or anything. ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Detect floppy diskette
On Tue, Aug 26, 2003 at 03:19:57PM -0500 or thereabouts, Charles Howse wrote: Try this: #!/usr/bin/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; Maybe I'm doing something wrong, all this script does is run and exit with status 0, whether I have a diskette in the drive or not. No output to screen or anything. Does nothing happen for 5 seconds? Good! That means you can trap the error. (Read my previous email). ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Detect floppy diskette
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 EOF to the end of this line 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 } remainder of bash script 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# insert floppy bash-2.05a# until FloppyInDrive; do echo please insert floppy and press enter; read key; done eject floppy 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 insert floppy eject floppy 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 insert floppy bash-2.05a# If the original errors, well, maybe the above will work anyway. Maybe it won't. Oh well. -- Josh ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]