Remote login and running a script on multiple servers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remote login and running a script on multiple servers
# 8  
Old 03-06-2014
Quote:
I repeat for the last time: Since you are using single quotes, how is the variable process defined on the remote systems so that it will be an exported variable in the environment of the shell started by rsh on those remote systems?
running on script is $HOST is short for the workstation${i} in a for loop where i =1 counting i<4
process is the variable name of process=/a path name/script name.sh

the problem is that Csh does not support stty operations on transit and
the output is ambiguous.
I see what you mean by the single and double quotes. I have to see what its doing.
thanks,
sorry i guess i didnt quite understand when you were talking about expanding. get back with ya on results and what i find out.
# 9  
Old 03-08-2014
Computer

It does not work correctly the way I want it to work. Csh is doing what it does best is keep the script running when you logout of the xterm. Plus I don't think you need the extra baggage of 2>&1 to get this accomplished. You get 3 dtexec pid on the local machine which in my case is undesirable and unwanted. That said; the process does start the remote systems with the script running in the back ground with the extra load of the dtexec process zombie.

Thanks Don for the help, I will have to figure something else out or a way to get rid of the zombies ("walkers").Smilie

below is the code I wanted to use but only tried the rsh segment to get results. Please note that there are missing segments due toSmilie company rules.Smilie

Code:
#!/bin/sh

# this is to start a process remotely and kill the process remotely

ScriptAndPath= #left out see below

# add insurance that $USER is ***
if [ $USER != $USER ]; then
    echo "You must be *** to run correctly with start & stop"
    exit
fi
#
# intentionally left out due to community overview.


case $1 in
    'start')
        for i in 1 2 3
            do
                rsh ws${i}host "${ScriptAndPath} 2&>1 &"
            done

        $ScriptAndPath #start on local system
    ;;

    'stop')

    # Search for processes that you've started based on the file write path
        for i in 1 2 3 4
        do
            rlogin ws${1}host
            sleep 8 #sleep for 8 sec
                # this should kill all process PID's for both script and dtexec
                for KILLPID in `ps -ef | grep proc | awk '{print $2}'`; do
                    kill -9 $KILLPID
                done
            exit
            sleep 8
        done            
    ;;
    
    *)
        echo "USAGE: $0 <start|stop>"
    ;;
esac

# 10  
Old 03-09-2014
There are a couple of strange things in this loop in the 'stop' case in your code:
Code:
    # Search for processes that you've started based on the file write path
        for i in 1 2 3 4
        do
            rlogin ws${1}host
            sleep 8 #sleep for 8 sec
                # this should kill all process PID's for both script and dtexec
                for KILLPID in `ps -ef | grep proc | awk '{print $2}'`; do
                    kill -9 $KILLPID
                done
            exit
            sleep 8
        done            
    ;;

In your 'start' case, you started processes on ws1host, ws2host, ws3host, and the local system. But here in your 'stop' case, you seem to want to rlogin to wsstophost four times and manually enter commands to be run on that host. You haven't told us what you typed into the first rlogin session, but the exit in the loop after the first rlogin session will terminate your script.

Assuming that the local system is ws4host, wouldn't the following come closer to doing what you said you want to do:
Code:
    # Search for processes that you've started based on the file write path
        for i in 1 2 3 4
        do
            rlogin ws${i}host <<"EOF"
                sleep 8 #sleep for 8 sec # I see no need for this line
                # this should kill all process PID's for both script and dtexec
                for KILLPID in `ps -ef | grep proc | awk '{print $2}'`; do
                    kill -9 $KILLPID
                done
                exit
EOF
            sleep 8 # I see no need for this line
        done            
    ;;

Changing ${1} to ${i} would seem to be crucial. Using a here-document to feed commands into rlogin would seem to be crucial. Trying to kill off every command on the system that happens to match the string proc seems dangerous. (Are you really sure that this string won't occur in the ps output from other processes that you don't intend to kill off?)
This User Gave Thanks to Don Cragun For This Post:
# 11  
Old 03-09-2014
Hi Don,

The first one was a typo, nice catch. I changed it on the original document just in case I ever want to go back and use it as reference.

Quote:
But here in your 'stop' case, you seem to want to rlogin to wsstophost four times and manually enter commands to be run on that host. You haven't told us what you typed into the first rlogin session, but the exit in the loop after the first rlogin session will terminate your script.
I cant put specific names out on public forums. It is a script and its path so you get a PID for the script. I am trying to now stop this script vita the PID
The exit command was for the rlogin but your right haven't thought that far in the script. I added the rest to post it for people can at least see what were talking about.

Quote:
Using a here-document to feed commands into rlogin would seem to be crucial.
I have to do some reading on this. Good tip thanks.

Code:
sleep 8 # I see no need for this line

this allows the connection to become stable before sending commands, there are other process that have to preform there task before you can send a task/command; for functional testing 8 is standard here don't ask me why I don't know.

Quote:
Trying to kill off every command on the system that happens to match the string proc seems dangerous. (Are you really sure that this string won't occur in the ps output from other processes that you don't intend to kill off?)
it works for testing for now and remember I cant post names, when i get more results on what starts up Ill get more specific. I can see it starts a bunch of daemon threads and its very undesirable it was ment to kill them as well dtexec threads. I believe i started with
Code:
pidof proc<name>

command but it did not show the daemon threads.

thanks again Don you are a great monitor and mentor.


As you can see testing is everything when you get to play with this guy Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error running grep on Remote Servers

Im running the below command sshpass -p mypassword ssh -t user1@server2 /bin/bash -c 'echo "mypassword" | sudo -S -l; echo "$?#`grep -iE "user66|dbuser|tomcat|splunk|stash|jira|user2|docadmin" /etc/passwd`"; exit' Below is the error I get: Output: I run this command across a... (1 Reply)
Discussion started by: mohtashims
1 Replies

2. Shell Programming and Scripting

Running a script on remote server kills my login session

Hi there, I'm trying to run a script remotely on a server in a particular directory named after hostname which already exists, my login session gets killed as soon as I run the below command. Not sure what is wrong, is there a better way to do it ? Note: I can also use nohup command to run... (14 Replies)
Discussion started by: mbak
14 Replies

3. Shell Programming and Scripting

Running set of commands in remote servers in shell script

Hi Wishing to all. I am very new joined in an organization as a unix system administrator. I need a help in preparing a script for a report. i have a file contains all of the linux/ubuntu servers line by line around 140 servers. vi servers.txt nh01 nh02 nh03 bh01 bh04 - - :wq (3 Replies)
Discussion started by: kumaraswamy
3 Replies

4. Shell Programming and Scripting

Shell script using expect to login to couple of remote servers and read "crontab -l"

I need a shell script using expect to login to couple of remote servers and read "crontab -l -u <username>" & "cat /etc/rc.local" & "df -h" and able to create output into a file saved locally with hostname.crontab & hostname.rc.local & disk.status. I can supply a file as list of hostname or IP... (4 Replies)
Discussion started by: jaipsharma
4 Replies

5. Solaris

Remote execution of a local script on multiple servers

So I have a scriptlet called solaris_command: for i in \ server1 server2 server3 do echo $i ssh $i $1 echo "" done I then use that as a command in multiple scripts to allow for data gathering for all virtual hosts in the environment thusly: solaris_command "cat... (3 Replies)
Discussion started by: os2mac
3 Replies

6. Shell Programming and Scripting

Running a script on multiple remote hosts at once

I have a script on about 15 hosts that I need to run for each host whenever I want (not crontab). Problem is, this script takes 5-10 mins to run for each host. Is there a way I can run the script in parallel for all the hosts instead of 1 at a time? Also, I'm remotely running the script on the... (3 Replies)
Discussion started by: mrskittles99
3 Replies

7. Shell Programming and Scripting

Prevent wrong user from using shell script for multiple remote servers

Hi, I am running a shell script from a central server to multiple remote servers using the following code: application_check() { # Linux/UNIX box with ssh key based login SERVERS=`cat /tmp/server-details` # SSH User name USR="user" # create new file > /tmp/abc.log # connect... (2 Replies)
Discussion started by: mystition
2 Replies

8. UNIX for Dummies Questions & Answers

Running the same remote script on multiple servers

Experts, Im trying to remote into a server, run a script that resides on that server and capture the information displayed & store in a local file. I struggled with this yesterday & finally that script is working now. Now, here is a scope creep and the script that I wrote for 1 remote... (2 Replies)
Discussion started by: OMLEELA
2 Replies

9. Shell Programming and Scripting

login into multiple servers through script is having some problem

Hi Everybody, I am bit new to shell scripting. I need some help in my script. I have to login into 15 servers and check some logs daily. For that I've written one shell script, somewhere it is having some problems. After log into the first server, the script is not going with the next steps.... (6 Replies)
Discussion started by: raghu.iv85
6 Replies

10. Shell Programming and Scripting

login into multiple servers thru script...

I need to login into multiple servers thru a script run couple commands and run find command as root. I only have ssh access to the servers as a user than I can "su" to root. If you have a similar script please post it. Also if you can suggest commands that I should consider please let me know. ... (1 Reply)
Discussion started by: avcert1998
1 Replies
Login or Register to Ask a Question