ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i want to run a script that will
1. login to a remote host
2. Run some command on the remote host
3. logout of the remote host.
i tried with this format...
*******************************
#!/bin/bash
rsh remotehost
......
commands
......
exit
*******************************
But when I run this script the specified commands run on my localhost & not the remote host.
Can any one please let me know how to make the commands( normal unix commnads mount & ls) on the remotehost ..... & also the exit command did not log me out of the remote host.
The trick is that rsh ends after your log out. It means you need to pass your commands to rsh, not keep as separate ones.
If you have a longer list of commands to do at the remote site, create a script with them. Then, change your main script in such a way that it first uploads the script with remote side commands (using scp, for instance) and then runs it using rsh - just add script name at the end of the rsh/ssh command. Finally you can remove the script you have run, also using rsh/ssh, this time with rm command.
Your suggestion worked for me.. the following script( scr ) worked for me.
******************************************
rsh remotehost001 <<EOF
mount
....
commands
.....
EOF
******************************************
But ..I m doing this to test about 100 machines( remotehost001 to remotehost100 ) around me. So I want to redirect this output to a particular file ( say reportfile ) on my localhost . But unable to do so.
When i run this script ( #./scr > reportfile ) the script logs onto other machine and closes too but I don get any result in the reportfile( this ile is on my localhost).
Please help me once again...
Where does the log go to when you run the script? To a file or to standard output? If to standard output, redirection should work. But if it goes to file, you need to copy it from the remote location (or open it remotely, from the server, on your machine).
It would probably be easier to put it into a script, in which case it should just be as simple as...
Code:
#!/bin/sh
LOGFILE=rsh.log
cat /dev/null > $LOGFILE
for HOST in host1 host2 host3 host4; do
rsh $HOST <<EOF >> $LOGFILE 2>&1
cat /etc/motd
hostname
uname -a
EOF
done
It should be perfectly fine to indent the rsh commands to make the script more readable, but you MUST place the ending EOF (or whatever tag you decide to use) at the BEGINNING of the line. Otherwise it won't get recognised and end the 'input'
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.