Sponsored Content
Top Forums Shell Programming and Scripting Until string from remote command equals value run remote command Post 302772103 by $scipt_Kid on Saturday 23rd of February 2013 02:40:26 AM
Old 02-23-2013
set variable value based on if string existing in output

I solved my issue by using the following code

Code:
#!/bin/bash
function GET_STATUS {
     #values Active Passive Failed
     ssh  -a localhost '/home/user/fakecommand.sh'
}

STATE="unknown"
until [[ "$STATE" = "Failed" ]]
do
echo $STATE
sleep 5


STATUS=`GET_STATUS`
echo $STATUS | grep Active && STATE="Active"
echo $STATUS | grep Passive && STATE="Passive"
echo $STATUS | grep Failed && STATE="Failed"
done







bash script: I want to wait until the output from function contains certain values

Note: this function ssh's into a remote server runs a command and outputs data to standard out



Code:
function GET_STATUS {    
     ssh  -a localhost '/home/user/fakecommand.sh'
}

Unfortunately the output from the remote command changes length in both line numbers and sometimes it has extra white space..

It looks something like this....



Running command.....


Code:
variable length:stuff i dont need1                stuff i dont need2                        status                          stuff i dont need3
variable length:stuff that i dont need 1                         stuff i dont need2                        Active                          stuff i dont need3

I want to perform actions based on the value of the status column
There are only 3 values..... Active,Passive,Failed

I have written the following code, but i think it could be much better.

Code:
GET_STATUS  | grep "Active" && STATE="Active" # I Set the variable first so that i dont have to wait for the sleep if it is already in Active
        until [[ "$STATE" = "Active" ]]
                do
                echo "Running GET_STATUS" && sleep 1
                GET_STATUS  | grep "Active" && STATE="Active"
done

Can anyone think of a way i can set the the variable $STATE
Any heap would be greatly appreciated


Thanks

Last edited by $scipt_Kid; 02-23-2013 at 09:59 AM.. Reason: I found a solution
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run remote EOF command

I have the command cat - << _EOF | ed /home/fred/test >/dev/null 2>&1 2 s#u_pwd=*:#u_pwd=${Password}:# 3,$ s/u_succhg#*:/u_succhg#${Date}:/ w q _EOF I works great on the local system but I need to ssh to a remote system and run this command without... (1 Reply)
Discussion started by: insania
1 Replies

2. Shell Programming and Scripting

ls command in Remote Server

Unix Box: IBM AIX Shell : K-Shell When i logged into a remote server through FTP, and tried to find only required month file by typing `ls -ltr *200805`, the output is "ls remotefile localfile". I coudnt understand this. What is want is get into the remote server and get the count of required... (6 Replies)
Discussion started by: vasuarjula
6 Replies

3. Shell Programming and Scripting

Run command on remote sever from script

I have two redhat linux server. i have created one script which contain some command that run on Local server as well as remote server.I am using this command to connect to remote server ssh user1@192.x.x.x 'command' but when i am running the script in local server it connecting to the server... (1 Reply)
Discussion started by: ranvijaidba
1 Replies

4. Shell Programming and Scripting

Need script to run the command in remote server

hi, I need script to perform below task. 1. Read the IP address 2. copy the script from origin server to destination. 3. get root access on destination server 4. run the script on destination server 5. return to the origin server Code: #!/bin/bash echo "Enter Server IP... (5 Replies)
Discussion started by: bapu1981
5 Replies

5. Shell Programming and Scripting

Check/get the exit status of a remote command executed on remote host through script

Geeks, Could you please help me out in my script and identify the missing piece. I need to check/get the exit status of a remote command executed on remote host through script and send out an email when process/processes is/are not running on any/all server(s). Here's the complete... (5 Replies)
Discussion started by: lovesaikrishna
5 Replies

6. UNIX for Beginners Questions & Answers

How to run command on remote server?

Hi I am trying to write a script which when I run from server A it execute few command on another server say B and show me the output. below is the script but it is not showing me the o/p of B machine but instead showing me A machine o/p every time. #!/bin/bash for i in `cat... (14 Replies)
Discussion started by: scriptor
14 Replies

7. Shell Programming and Scripting

Run awk command on remote host

I have below command to check for error logs from last 24 hours from the file : /var/log/messages/ The command is working fine on the local host. sudo awk -F - -vDT="$(date --date="24 hours ago" "+%b %_d %H:%M:%S")" ' DT < $1' /var/log/messages | egrep -i "error|fail" I want to run the... (8 Replies)
Discussion started by: rahul2662
8 Replies

8. Shell Programming and Scripting

Run remote command and send email

I am currently try to write a simple script with the following condition, but so far not having luck as the exit code would always be 0. Run remote command to read a file and grep for test word. if test word is in the file, send email. if not, do nothing also possible to ssh to multiple... (3 Replies)
Discussion started by: jaapar
3 Replies

9. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

10. UNIX for Beginners Questions & Answers

Remote command in PuTTY

I have an issue with all of my AIX servers where a user can execute a remote command (bash in this case) using PuTTY and bypass all of the application security that we setup in the users .profile. How do I secure this without breaking the rest of the users? (8 Replies)
Discussion started by: d_brodie
8 Replies
dat_ep_modify(3DAT)				     Direct Access Transport Library Functions				       dat_ep_modify(3DAT)

NAME
dat_ep_modify - change parameters of an Endpoint SYNOPSIS
cc [ flag... ] file... -ldat [ library... ] #include <dat/udat.h> DAT_RETURN dat_ep_modify ( IN DAT_EP_HANDLE ep_handle, IN DAT_EP_PARAM_MASK ep_param_mask, IN DAT_EP_PARAM *ep_param ) PARAMETERS
ep_handle Handle for an instance of the Endpoint. ep_param_mask Mask for Endpoint parameters. ep_param Pointer to the Consumer-allocated structure that contains Consumer-requested Endpoint parameters. DESCRIPTION
The dat_ep_modify() function provides the Consumer a way to change parameters of an Endpoint. The ep_param_mask parameter allows Consumers to specify which parameters to modify. Providers modify values for ep_param_mask requested parameters only. Not all the parameters of the Endpoint can be modified. Some can be modified only when the Endpoint is in a specific state. The following list specifies which parameters can be modified and when they can be modified. Interface Adapter Cannot be modified. Endpoint belongs to an open instance of IA and that association cannot be changed. Endpoint State Cannot be modified. State of Endpoint cannot be changed by a dat_ep_modify() operation. Local IA Address Cannot be modified. Local IA Address cannot be changed by a dat_ep_modify() operation. Local Port Qualifier Cannot be modified. Local port qualifier cannot be changed by a dat_ep_modify() operation. Remote IA Address Cannot be modified. Remote IA Address cannot be changed by a dat_ep_modify() operation. Remote Port Qualifier Cannot be modified. Remote port qualifier cannot be changed by a dat_ep_modify() operation Protection Zone Can be modified when in Quiescent, Unconnected, and Tentative Connection Pending states. Protection Zone can be changed only when the Endpoint is in quiescent state. The only Endpoint states that isare quiescent isare DAT_EP_STATE_UNCONNECTED and DAT_EP_STATE_TENTATIVE_CONNECTION_PENDING. Consumers should be aware that any Receive DTOs currently posted to the Endpoint that do not match the new Protection Zone fail with a DAT_PROTECTION_VIOLATION return. In DTO Event Dispatcher Can be modified when in Unconnected, Reserved, Passive Connection Request Pending, and Tentative Connection Pending states. Event Dispatcher for incoming DTOs (Receive) can be changed only prior to a request for a connection for an Active side or prior to accepting a Connection Request for a Passive side. Out DTO Event Dispatcher Can be modified when in Unconnected, Reserved, Passive Connection Pending, and Tentative Connection Pending states. Event Dispatcher for outgoing DTOs (Send, RDMA Read, and RDMA Write) can be changed only prior to a request for a connection for an Active side or prior to accepting a Connection Request for a Passive side. Connection Event Dispatcher Can be modified when in Unconnected, Reserved, Passive Connection Pending, and Tentative Connection Pending states. Event Dispatcher for the Endpoint Connection events can be changed only prior to a request for a connection for an Active side or accepting a Connection Request for a Passive side. Service Type Can be modified when in Unconnected, Reserved, Passive Connection Pending, and Tentative Connection Pending states. Service Type can be changed only prior to a request for a connection for an Active side or accepting a Connection Request for a Passive side. Maximum Message Size Can be modified when in Unconnected, Reserved, Passive Connection Request Pending, and Tentative Connection Pending states. Maximum Message Size can be changed only prior to a request for a connection for an Active side or accepting a Connection Request for a Passive side. Maximum RDMA Size Can be modified when in Unconnected, Reserved, Passive Connection Pending, and Tentative Connection Pending states. Maximum RDMA Size can be changed only prior to a request for a connection for an Active side or accepting a Connection Request for a Passive side. Quality of Service Can be modified when in Unconnected, Reserved, Passive Connection Pending, and Tentative Connection Pending states. QoS can be changed only prior to a request for a connection for an Active side or accepting a Connection Request for a Passive side. Recv Completion Flags Can be modified when in Unconnected, Reserved, Passive Connection Pending, and Tentative Connection Pending states. Recv Completion Flags specifies what DTO flags the Endpoint should support for Receive DTO operations. The value can be DAT_COMPLE- TION_NOTIFICATION_SUPPRESS_FLAG, DAT_COMPLETION_SOLICITED_WAIT_FLAG, or DAT_COMPLETION_EVD_THRESHOLD_FLAG. Recv posting does not sup- port DAT_COMPLETION_SUPPRESS_FLAG or DAT_COMPLETION_BARRIER_FENCE_FLAG dat_completion_flags values that are only applicable to Request postings. Recv Completion Flags can be changed only prior to a request for a connection for an Active side or accepting a Connection Request for a Passive side, but before posting of any Recvs. Request Completion Flags Can be modified when in Unconnected, Reserved, Passive Connection Request Pending, and Tentative Connection Pending states. Request Completion Flags specifies what DTO flags the Endpoint should support for Send, RDMA Read, RDMA Write, and RMR Bind operations. The value can be: DAT_COMPLETION_UNSIGNALLED_FLAG or DAT_COMPLETION_EVD_THRESHOLD_FLAG. Request postings always support DAT_COMPLE- TION_SUPPRESS_FLAG, DAT_COMPLETION_SOLICITED_WAIT_FLAG, or DAT_COMPLETION_BARRIER_FENCE_FLAG completion_flags values. Request Comple- tion Flags can be changed only prior to a request for a connection for an Active side or accepting a Connection Request for a Passive side. Maximum Recv DTO Can be modified when in Unconnected, Reserved, Passive Connection Pending, and Tentative Connection Pending states. Maximum Recv DTO specifies the maximum number of outstanding Consumer-submitted Receive DTOs that a Consumer expects at any time at the Endpoint. Maximum Recv DTO can be changed only prior to a request for a connection for an Active side or accepting a Connection Request for a Passive side. Maximum Request DTO Can be modified when in Unconnected, Reserved, Passive Connection Pending, and Tentative Connection Pending states. Maximum Request DTO specifies the maximum number of outstanding Consumer-submitted send and RDMA DTOs and RMR Binds that a Consumer expects at any time at the Endpoint. Maximum Out DTO can be changed only prior to a request for a connection for an Active side or accepting a Connection Request for a Passive side. Maximum Recv IOV Can be modified when in Unconnected, Reserved, Passive Connection Pending, and Tentative Connection Pending states. Maximum Recv IOV specifies the maximum number of elements in IOV that a Consumer specifies for posting a Receive DTO for the Endpoint. Maximum Recv IOV can be changed only prior to a request for a connection for an Active side or accepting a Connection Request for a Passive side. Maximum Request IOV Can be modified when in Unconnected, Reserved, Passive Connection Pending, and Tentative Connection Pending states. Maximum Request IOV specifies the maximum number of elements in IOV that a Consumer specifies for posting a Send, RDMA Read, or RDMA Write DTO for the Endpoint. Maximum Request IOV can be changed only prior to a request for a connection for an Active side or accepting a Connection Request for a Passive side. Maximum outstanding RDMA Read as target Can be modified when in Unconnected, Reserved, Passive Connection Pending, and Tentative Connection Pending states. Maximum number of outstanding RDMA Reads for which the Endpoint is the target. Maximum outstanding RDMA Read as originator Can be modified when in Unconnected, Reserved, Passive Connection Pending, and Tentative Connection Pending states. Maximum number of outstanding RDMA Reads for which the Endpoint is the originator. Num transport-specific attributes Can be modified when in Quiescent (unconnected) state. Number of transport-specific attributes to be modified. Transport-specific endpoint attributes Can be modified when in Quiescent (unconnected) state. Transport-specific attributes can be modified only in the transport-defined Endpoint state. The only guaranteed safe state in which to modify transport-specific Endpoint attributes is the quiescent state DAT_EP_STATE_UNCONNECTED. Num provider-specific attributes Can be modified when in Quiescent (unconnected) state. Number of Provider-specific attributes to be modified. Provider-specific endpoint attributes Can be modified when in Quiescent (unconnected) state. Provider-specific attributes can be modified only in the Provider-defined Endpoint state. The only guaranteed safe state in which to modify Provider-specific Endpoint attributes is the quiescent state DAT_EP_STATE_UNCONNECTED. RETURN VALUES
DAT_SUCCESS The operation was successful. DAT_INVALID_HANDLE The ep_handle parameter is invalid. DAT_INVALID_PARAMETER The ep_param_mask parameter is invalid, or one of the requested Endpoint parameters or attributes was invalid, not supported, or cannot be modified. DAT_INVALID_STATE Parameter in an invalid state. The Endpoint was not in the state that allows one of the parameters or attributes to be modified. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard: uDAPL, 1.1, 1.2 | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
libdat(3LIB), attributes(5) SunOS 5.10 16 Jul 2004 dat_ep_modify(3DAT)
All times are GMT -4. The time now is 06:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy