0

I want to create filesystem on remote machines VIA ssh in my bash script

 disk=sdg

the following line is from my bash script

 ssh $IP  " [[ `  lsblk -f | grep $disk | awk '{print NF}' ` -eq 1 ]] &&  
 mkfs.ext4  -j -m 0 /dev/$disk -F "
 bash: -c: line 0: conditional binary operator expected
 bash: -c: line 0: syntax error near `1'
 bash: -c: line 0: ` [[  -eq 1 ]] &&  mkfs.ext4  -j -m 0 /dev/ -F '

while the following syntax will return 1 in case file system not created on disk

lsblk -f | grep $x | awk '{print NF}'

so I just want to perform VIA ssh case if filesystem not created then I will execute the mkfs

is it possible?

shalom
  • 451
  • 12
  • 26

1 Answers1

0

I think you're running into a shell expansion problem here. My guess is that the subcommand (in back ticks) is being executed locally, not on the remote system.

I'd suggest creating the bash script locally, copying it to the remote server and then executing it there.

toppledwagon
  • 4,215
  • 24
  • 15