[Techtalk] bash: test for correct host

aec brat at magma.ca
Sat Aug 28 09:19:07 EST 2004


I would like to idiot proof a bash script.

I have  3 hosts, all with the same username and identical
home directories. 

Ideally I would like to sync these directories each night.

So if im working on server - /home/me
                 or laptop - /home/me
                 or desktop -/home/me

I can run a script, kept in my ~/bin that tests for which host I am on
and then rsyncs my ~/ to the other two machines.

so I would likely use "case" for this?

I can manage to hack up the rsync part of the script, if someone could
point out the right structure perhaps? do i use elseif, or case etc...


the one syntax part I cant figure out is to
test for hostname.


#!/bin/bash
# test script

if [$HOSTNAME="desktop"];
then

    echo "host ok"

else
    
    echo "host not ok"

fi    

This dosent work, with the error,
bash: [desktop: command not found

I think I am in the "close but no cigar" area here!

-- 
Angelina Carlton


More information about the Techtalk mailing list