I want to get the last folders name from a pi and this commands works just fine:
ssh pi@192.168.6.24 'ls -t /media/usb/Pictures/new/ | head -1'
Returns: 230125_1356
To retrieve the number of files in that folder I'm using:
ssh pi@192.168.6.24 ls -t /media/usb/Pictures/new/$(ssh pi@192.168.6.24 'ls -t /media/usb/Pictures/new/ | head -1')/ | wc -l
Returns: 5
But now I'm trying to get the same results from another pi connected to the first one: This one works fine and gives me the name of the last folder:
ssh -t pi@192.168.6.24 ssh pi@192.168.0.50 'ls -t /media/usb/Pictures/new/ | head -1'
Returns: 230125_1356
My problem arises when I try to get the number of files inside the last folder over the second pi with:
ssh -t pi@192.168.6.24 ssh pi@192.168.0.50 ls -t /media/usb/Pictures/new/$(ssh -t pi@192.168.6.24 ssh pi@192.168.0.50 ls -t /media/usb/Pictures/new/ | head -1)/ | wc -l
Returns: 1
The return should be 4 which is the number of files in that folder.
Any help will be much appreciated. Thanks.
sshfs
if you do this a lot. Parsing the output ofls
should be avoided. – Panki Jan 26 '23 at 07:57sudo sshfs -o sshfs_debug laptop@192.168.6.89:/ /mnt/field_laptop
SSHFS version 2.10.0 laptop@192.168.6.89's password: Server version: 3 Extension: posix-rename@openssh.com <1> Extension: statvfs@openssh.com <2> Extension: fstatvfs@openssh.com <2> Extension: hardlink@openssh.com <1> Extension: fsync@openssh.com <1>
– Mark Jan 26 '23 at 14:11