Automated a script that will login to another unix box and run a shell script on that box...

Posted on 2004-11-29
Last Modified: 2013-12-06
I'm trying to create a shell script that I could run using KRON or manually that would do the following:

1.  telnet to another unix box (Sun OS 5.6).  The originating Unix box is HP UX 12.0 64bit.
2.  While logged on to the 2nd box, run a shell script in a specified directory.  This script is already in place and runs on demand.
3.  Logout of second box.

What do I need to setup on the source and target boxes to make this work?

Question by:bmickey
    LVL 16

    Expert Comment

    It would be better if instead of using telnet, you'd prefer using rsh/ssh.


    Author Comment

    I don't care what I'm using , my main goal is to be able to automated a script on another server from the first server.
    LVL 16

    Accepted Solution

    In that case, you will have to use the $HOME/.rhosts and /etc/rhosts.equiv files.
    $HOME/.rhosts will contain entries for which user can be trusted.

    If a user/group is trusted for a particular rhosts file, then the user can login without supplying an id/password

    see this for further

    after that, you may use .telnetrc if it serves your purpose.....


    LVL 48

    Assisted Solution

    Please use ssh, then it is as simple as setting up ssh keys then doing:

    ssh remotehost /script/to/run
    LVL 14

    Expert Comment

    Also... HP-UX 12.0?

    The latest version is 11.22, with 11.23 expected in the next couple of months and 11.30 some time next year.
    LVL 38

    Assisted Solution


      For ssh login without password, you need
    1. Login as userA on machineA and run the following commands:
       $ssh-keygen -t dsa
       $ssh-keygen -t rsa
    Note : Accept the default

    The above would generate 4 files under $HOME/.ssh

    cd $HOME/.ssh
    cat > authorized_keys
    cat >> authorized_keys
    chmod 700 authorized_keys

    2. Now copy this authorized_keys (which you created as above) to the home dir of the destination machine.
     In your case machineB and userA (since the user name is same on both nodes).

    3. For all machines,
    check sshd_config (/etc/ssh/sshd_config) file to make sure that it contains the following entry
    PubkeyAuthentications yes

    chech ssh_config (/etc/ssh/ssh_config) file for the following entry
    ForwardAgent yes

    4. Now you would be able to execute the commands on dest host without asking for password.
    No matter what is the password you have for both accounts.

    For example:
    $ ssh <remote hostname> <command>


    LVL 38

    Assisted Solution

    If you don't worry about security, you can use rsh (setup .rhosts file etc) use:
       rsh remote-host /path-to/script

    Better to use secure ssh, setup ssh login without password (otherwise use expect
    script to handle the password), and use

    ssh login@remote-host "/path-to/script"
    LVL 11

    Assisted Solution

    for similar automated purpose I use expect scripts
    one downside is that , I need to have my password in clear text inside the script , ofcourse you can make the script readable only by you

    Expert Comment

    I have 2 basic doubts
    1. I am trying to read command line (input typed by user) and then check the same. Pl see the script below
    echo "To run application press 1"
    read input
    if [ "$input"=1 ]; then
    echo "Pressed 1"
    elif [ "$input" =2 ]; then
    When I run the script gives follwing errors-
    ': not a valid identifieread: `input
    ./ line 9: syntax error near unexpected token `elif'
    '/ line 9: `elif [ "$input" =2 ]; then

    2. I am writting a shell script-
    If I put the first statement  in shell script file as  
    When I run the script I get "file not found" error

    Please clarify the same

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
    Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now