plan9port/src/cmd/netfiles/netfilestat

47 lines
635 B
Text
Raw Normal View History

2005-03-18 19:30:22 +00:00
#!/usr/local/plan9/bin/rc
if(! ~ $#* 2){
2005-03-20 23:39:48 +00:00
echo usage: netfilestat system path >[1=2]
2005-03-18 19:30:22 +00:00
exit usage
}
f=dostat
2005-03-21 07:37:34 +00:00
. netfilelib.rc $1
2005-03-18 19:30:22 +00:00
fn dostat {
{
2005-03-21 07:37:34 +00:00
9 echo -cd $2
} | mysftp $1 >$t
if(9 test -e $t -a ! -s $t){
2005-03-18 19:30:22 +00:00
echo directory
exit 0
}
2005-03-21 07:37:34 +00:00
if(9 grep -s 'Can''t change directory|is not a directory' $t){
2005-03-18 19:30:22 +00:00
echo file
exit 0
}
2005-03-21 07:37:34 +00:00
if(9 grep -s 'Couldn''t stat remote file|such file' $t){
echo nonexistent
2005-03-18 19:30:22 +00:00
exit 0
}
2005-03-21 07:37:34 +00:00
cat $t >[1=2]
echo unknown error
2005-03-18 19:30:22 +00:00
exit 0
}
fn dostat9p {
if(! 9p ls -ld $1/$2 >$t >[2]/dev/null){
echo nonexistent
exit 0
}
if(9 grep -s '^d' $t){
echo directory
exit 0
}
echo file
exit 0
}
$f $1 $2