I am trying to get the latest folder inside my directory in machineB and machineC. So I came up with the below command which will find me the latest folder inside -
`/bat/data/snapshot`
And that latest folder will be in the form of YYYYMMDD
. Below is my shell script -
#!/bin/bash
readonly FILERS_LOCATION=(machineB machineC)
readonly MAPPED_LOCATION=/bat/data/snapshot
dir1=$(ssh -o "StrictHostKeyChecking no" david@${FILERS_LOCATION[0]} ls -dt1 "$MAPPED_LOCATION"/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] | head -n1)
dir2=$(ssh -o "StrictHostKeyChecking no" david@${FILERS_LOCATION[1]} ls -dt1 "$MAPPED_LOCATION"/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] | head -n1)
echo $dir1
echo $dir2
Now dir1
will look like in machineB
as -
/bat/data/snapshot/20131222
And dir2
will look like in machineC
as -
/bat/data/snapshot/20131222
Now I need to cd
into these two directory and do a word count of files and store them in length1 and length2 variable -
ls | wc -l
I thought I can do this but I thought before that I need to cd into those two directory and then do a word count -
echo $dir1
echo $dir2
length1=$(ssh -o "StrictHostKeyChecking no" david@${FILERS_LOCATION[0]} ls | wc -l "$dir1")
length2=$(ssh -o "StrictHostKeyChecking no" david@${FILERS_LOCATION[1]} ls | wc -l "$dir2")
echo $length1
echo $length2
So now I am not sure how to do cd into those two directory and then do a ls
and find the count of files as part of that shell script?