Sponsored Content
Top Forums Shell Programming and Scripting Execute a local script against a remote server Post 302842313 by Just Ice on Thursday 8th of August 2013 10:40:12 PM
Old 08-08-2013
you are trying to run an interactive script non-interactively ...
Code:
echo " if you want to record the cpu utilization for specific time period press y else press enter "
read ip

you need to make the script able to run non-interactively ... modifications to your original script in red font ...

also, if not already there -- please get into the habit of using indents as that really helps everybody debug your code ...

to run script remotely ... notice the shortened ssh command line with the y argument ...
Code:
ssh username@servernname "/dir/scriptname y"

Code:
#!/bin/ksh
ip=$1
function record
{
((end = $(date +%s) + $second))
while [ $(date +%s) -lt $end ]
do
    echo $end
    echo $(date +%s)
    (ps aux|head -10 && echo " " ) >> testing.txt
    sleep 1
    done
}
echo " This script displays cpu utilization of currently running processes on the remote server and record the the data for a period if required"
op=`ps aux | head -10`
echo " "
sleep 2
if [ ! $ip ]
then
    echo " if you want to record the cpu utilization for specific time period press y else press enter "
    read ip
fi
if [[ "$ip" == "y" ]]
then
    echo " enter the time to be recorded in seconds eg:5"
    second=$2
    echo " cpu utilization is being recorded at ~/cpuutilreport.txt, open the file after `expr 10 + $second ` seconds"
    sleep 2
    echo "$op"
    record
    sleep 1
else
    echo "cpu utilization of currently running processes (top 10 cpu consuming only)"
    echo " "
    sleep 2
    echo "$op"
fi

exit 0

This User Gave Thanks to Just Ice For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

executing a remote location script from local server

hi i am having two servers one is local and remote(FTP)server.from local server i have to connect to remote server and execute a shell script i want to run a shell script(remote location) from my local server i am having some knowledge on ftp but i am not getting the result .please give ... (2 Replies)
Discussion started by: srivsn
2 Replies

2. Shell Programming and Scripting

Can a script runned in local server access remote server?

Hi, Im creating a script that is supposed to run commands on remote server using sftp. My script is as below: #!/bin/ksh sftp remote_server mypassword cd /u08/mydir/allfiles mget * .. But this is what I got when I runned the script: Connecting to remote server...... (3 Replies)
Discussion started by: luna_soleil
3 Replies

3. Shell Programming and Scripting

How to stop a script running in remote server from local script

Hi, I have googled for quite some time and couldn't able to get what exactly I am looking for.. My query is "how to stop a shell script which is running inside a remote server, using a script"??? can any one give some suggestions to sort this out. (1 Reply)
Discussion started by: mannepalli
1 Replies

4. Shell Programming and Scripting

rsh help - getting the output of remote script to local server.

Hi, I have a script that runs for an hour. Have to run it on remote server and need the output it produces on the remote server to decide for failure or success. I run it through a Autosys Job which logs the outputs, both 1 & 2. I use the commands 1) rsh <SERVER> 'nohup /tmp/xyz.ksh &' 2)... (5 Replies)
Discussion started by: aster007
5 Replies

5. Shell Programming and Scripting

Executing local script/command on remote server

I have a command that I want to run on machine B from machine A. If I run the command on machine B locally, it works fine. Here is the command: for n in `find /data1/ -name 'ini*.ext'` ; do echo cp $n "`dirname $n `/` basename $n .ext`"; done From machine A, I issue this command ... (3 Replies)
Discussion started by: dirtyd0ggy
3 Replies

6. Solaris

Script to get files from remote server to local server through sftp without prompting for password

Hi, I am trying to automate the process of fetching files from remote server to local server through sftp. I have the username and password for the remote solaris server. But I need to give password manually everytime i run the script. Can anyone help me in automating the script such that it... (3 Replies)
Discussion started by: ssk250
3 Replies

7. Shell Programming and Scripting

How to Append the output of a script running in remote server to a file in local server?

Hi guys, So i am in server1 and i have to login to server 2, 3,4 and run some script there(logging script) and output its result. What i am doing is running the script in server2 and outputting it to a file in server 2 and then Scp'ing the file to server1. Similarly i am doing this for other... (5 Replies)
Discussion started by: srkmish
5 Replies

8. Shell Programming and Scripting

How can I execute local script on remote machine and include arguments?

I have a script in local server cd /home/dell/work/BOP/testdir ./processchk po (here processchk is a script & po is passed as an argument) Now I want to execute this script from remote server ssh $username@$hostname "cd /home/dell/work/BOP/testdir; ./processchk po" But Its getting error... (9 Replies)
Discussion started by: manohar2013
9 Replies

9. Shell Programming and Scripting

How to execute commands on remote server using expect script?

I need to copy python script file to around 100 servers using expect script. 1. Copy script to my user home first(/home/myhome) on each remote server 2. change permissions on copied file to 766. 3. sudo to appuser1 account on remote server. copy script file from my user home to /usr/bin/... (1 Reply)
Discussion started by: kchinnam
1 Replies

10. Shell Programming and Scripting

Except script to run a local shell script on remote server using root access

local script: cat > first.sh cd /tmp echo $PWD echo `whoami` cd /tmp/123 tar -cvf 789.tar 456 sleep 10 except script: cat > first #!/usr/bin/expect set ip 10.5.15.20 set user "xyz123" set password "123456" set script first.sh spawn sh -c "ssh $user@$ip bash < $script" (1 Reply)
Discussion started by: Aditya Avanth
1 Replies
cmdo(1m)																  cmdo(1m)

NAME
cmdo - Execute process on multiple remote Serviceguard nodes. SYNOPSIS
cmdo [[-n node_name]...] [-t timeout] command DESCRIPTION
cmdo will execute a process on a multiple remote Serviceguard nodes and return any output or return value. cmdo is limited in several ways. cmdo is best suited for situations where other remote execution facilities are not available. For a more full featured tool for remote execution within a cluster, see cexec(1m) provided by Distributed Systems Administration Utilities. To use this command, the local user must have the root access role on each of the involved nodes. For more information on Serviceguard access control policies, see the manual, Managing Serviceguard. To use the cmdo command without specifying -n options, the local node must be configured into a Serviceguard cluster. If no -n options are specified, the command will be executed on all available nodes in the cluster. The command will be executed in an environment which matches the local node. All environment variables defined locally will be available on the remote node. Output from stderr and stdout for the remote process will be combined and delivered in one transmission. This command should not be used for interactive commands or commands which will return large quantities of output. Output from each node will be displayed sequentially as the operation is executed on each remote node. Input via stdin is not supported. Killing the cmdo process does not stop any remote executions of the command. cmdo should not be used on any command which may hang without specifying a timeout value. Options And Arguments -t timeout Kill the executed command if it does not exit within the specified timeout (in seconds) -n node_name Serviceguard node to execute command on. If no -n options are specified, all the nodes configured in the cluster are used. command Command to execute on remote node. May be quoted. RETURN VALUE
cmdo returns the following values: 0 Successful completed on all nodes. >0 Command failed on one or more nodes with the specified exit value. EXAMPLES
Execute an 'ls' in a remote directory on all nodes within the cluster. cmdo ls /tmp Execute an 'ls' in a remote directory on two nodes not configured within a Serviceguard cluster. cmdo -n node1 -n node2 ls /tmp AUTHOR
cmdo was developed by HP. SEE ALSO
cexec(1m), cmcp(1m), cmexec(1m), cmsync(1m), cmquerycl(1m), cmviewcl(1m) Requires Optional Serviceguard Software cmdo(1m)
All times are GMT -4. The time now is 09:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy