Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2004-11-29
Medium Priority
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

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


Author Comment

ID: 12697596
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

manav_mathur earned 400 total points
ID: 12697761
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.....


Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 48

Assisted Solution

Tintin earned 400 total points
ID: 12700179
Please use ssh, then it is as simple as setting up ssh keys then doing:

ssh remotehost /script/to/run
LVL 14

Expert Comment

ID: 12700828
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

wesly_chen earned 400 total points
ID: 12700968

  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 id_dsa.pub > authorized_keys
cat id_rsa.pub >> authorized_keys
rm id_dsa.pub id_rsa.pub
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

yuzh earned 400 total points
ID: 12701784
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

avizit earned 400 total points
ID: 12702089
for similar automated purpose I use expect scripts http://expect.nist.gov/
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

ID: 13062580
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
./file.sh: line 9: syntax error near unexpected token `elif'
'/file.sh: 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

581 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