I have a below shell script which will get the latest folder from my current 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
length1=$(ssh -o "StrictHostKeyChecking no" david@${FILERS_LOCATION[0]} "ls '$dir1' | wc -l")
length2=$(ssh -o "StrictHostKeyChecking no" david@${FILERS_LOCATION[1]} "ls '$dir2' | wc -l")
echo $length1
echo $length2
if [ $dir1 eq $dir2 ] && [length1 > 0] && [length2 > 0]
then
echo "Hello World"
Now I need to write conditional if statement. I need to check whether dir1
is equal to dir2
and length1
is greater than 0
and length2
is also greater than 0
then only print outs Hello World
But somehow my above if statement doesn't work. Any idea what wrong I am doing here? I am little bit rusty in bash scripting..