Find the answer to your Linux question:
Results 1 to 4 of 4
Hi All, I am new to scripting, would like to have a script that tests whether a directory exists on remote host & display the message accordingly. The remote hostname ...
  1. #1
    Just Joined!
    Join Date
    Aug 2010
    Posts
    6

    Shell script to check whether directory exists on remote server

    Hi All,

    I am new to scripting, would like to have a script that tests whether a directory exists on remote host & display the message accordingly. The remote hostname can be provided by means of file containing list of hostnames. Can use rsh for connecting to remote host.

    I tried with couple of scripts by searching google but didn't get desired result. Please help me, below is my efforts, $file contains list of hostnames.

    for i in $file
    do
    if ( [ `rsh $i test -d /tmp/.X*` ] || [ `rsh $i test -d /scratch/.X*` ] )
    then
    echo "directory exist"
    else
    exit 0;
    fi
    done

    Thanks in advance, appreciate all the efforts.

  2. #2
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568
    I would use ssh instead of rsh - rsh is unsecured and very old.
    localhost#ssh user@remote "[ -d /tmp ]"
    localhost#echo $?
    localhost#ssh user@remote "[ -d /xyz ]"
    localhost#echo $?
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  3. #3
    Just Joined!
    Join Date
    Aug 2010
    Posts
    6
    I agree ssh is more secure than rsh, would like to test the condition whether directory exists on remote server & also display message accordingly if it exists, the condition has to be run inside a loop as the number of hosts to be tested are many & hostnames are passed as $file in the script.

    Thanks for the help.

    Quote Originally Posted by Lakshmipathi View Post
    I would use ssh instead of rsh - rsh is unsecured and very old.

  4. #4
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568
    Can you create passwordless ssh login ?
    for i in {1..10};
    do
    ssh user@client$i "[ -d /xyz ]"
    if [$? -eq 0]
    then
    echo "exists"
    fi
    done
    Try "pdsh" thats more powerful than rsh or ssh.
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...