Sponsored Content
Full Discussion: ssh connection script
Top Forums Shell Programming and Scripting ssh connection script Post 302089764 by BOFH on Wednesday 20th of September 2006 04:30:52 PM
Old 09-20-2006
My retrieval script uses a timeout similar to yours. The process id is stored in $! though:

Code:
    if [ $SERVER = $JUMP ]
    then
      scp -q $SERVER:$SERVER/$CONTENT $SVRPATH & > /dev/null 2>&1
      PID=$!
    else
      scp -q $JUMP:$SERVER/$CONTENT $SVRPATH & > /dev/null 2>&1
      PID=$!
    fi

# wait for the specified number of seconds for scp to complete
# if the timeout is exceeded, kill the process and move on to the next box

    while [[ $TIMEOUT -gt 0 ]]
    do
      /usr/bin/ps -p $PID > /dev/null 2>&1
      if [[ $? -ne 0 ]]
      then
        break
      fi
      TIMEOUT=$(($TIMEOUT - 1))
      sleep 1
    done

# if the timeout reaches 0, then the process was killed. Report something.

    if [[ $TIMEOUT -le 0 ]]
    then
      echo "ERROR: Unable to connect to server ($PROGNAME)" >> $SVRPATH/config.status
      chmod 664 $SVRPATH/config.status
      kill -KILL $PID
    fi

Carl
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Testing ssh connection from KSH script

Hi. I have a kornshell script that runs on a daily basis as a cron job. Part of what the script does is copy the folder contents from another server to the current server (server where KSH script is running). I have a scp command, as follows: scp $REMOTE_HOST:$REMOTE_FILE_DIR/* $TMP_DIR ... (8 Replies)
Discussion started by: dmilks
8 Replies

2. Shell Programming and Scripting

Remote SSH Connection Using Script

Hi, I am new to Shell Scripting. Can anybody help me in writing a Script Which Could Login from a Unix box to a Remote Unix box which accepts the user credentials automatically and display the result for checking the Disk Space Utilisation (Without running any SSH agent). (1 Reply)
Discussion started by: ajith_tg
1 Replies

3. Shell Programming and Scripting

how to terminate ssh connection without terminating script

Hi all, I connect with SSH connection to remote machine in the script and ı want to logout at half of the script then continue to script. If ı write exit in the script it terminates script not SSH connection. How can i do that please help me (1 Reply)
Discussion started by: fozay
1 Replies

4. Shell Programming and Scripting

SSH Connection drops - but does my script keep running?

Hello there. I'm fairly new to Linux, but I am connecting via SSH and PuTTY to a remote server, and I am running a fairly heavy MySQL script in a PHP page. Our connection here is dodgy to say the least and I get continuous disconnections. My question is, when I get disconnected, does my... (4 Replies)
Discussion started by: christatedavies
4 Replies

5. Shell Programming and Scripting

Mysql command after a SSH connection (Script)

Hi all, Im new at scripting and i need to run a few commands at work every hours so i decide to make a script but on 1 of the steps i have a the follwoing problem: The command i do is this: #!/bin/bash ssh root@asdasd001 'mysql -h A-db-1 -uroot -password --execute "show slave status"'... (3 Replies)
Discussion started by: Aparicio
3 Replies

6. Shell Programming and Scripting

Passing password in script for ssh connection - no except

Used the script posted on forum - unix.com/shell-programming-scripting/21597-script-change-passwords-same-user-multiple-servers.html but the last question posted on this seems to be still unanswered, tried different things with no success, can someone help giving an way to pass the password via... (5 Replies)
Discussion started by: sapadmin
5 Replies

7. Shell Programming and Scripting

How to automate SSH remote connection with a shell script

Hi Guys! I am trying to write a shell script for automated ssh. vairable user and passwd have initialized correctly, but when I use the following it still prompting me for the password. #!/usr/bin/bash user='root@10.14.76.225' passwd='admin' ssh $user $passwd uptime exit I... (3 Replies)
Discussion started by: pinpe
3 Replies

8. Shell Programming and Scripting

ssh connection through shell script with no interruption

Hi all, I need ssh in shell script. My requirement is: - Take user_name and password from user (in PHP) - Pass this to shell script which will: - connect via ssh - Run sql query - Pass the results back in PHP - Put the results to website. I know PHP has libraries for ssh and ftp, but... (3 Replies)
Discussion started by: shekhar2010us
3 Replies

9. UNIX for Dummies Questions & Answers

Script that tries to connect via SSH till connection is up

Hey, I need a script that tries to connect via SSH to a remote server and that remote server might not be up yet, so retry until succeed the error message I get if the server is not up yet is: ssh: connect to host 127.0.0.1 port 40001: Connection refused any idea of a good way to do it ? ... (5 Replies)
Discussion started by: OdedOvdat
5 Replies

10. UNIX for Beginners Questions & Answers

Ssh script to validate ssh connection to multiple serves with status

Hi, I want to validate ssh connection one after one for multiple servers..... password less keys already setup but now i want to validate if ssh is working fine or not... I have .sh script like below and i have servers.txt contains all the list of servers #/bin/bash for host in $(cat... (3 Replies)
Discussion started by: sreeram4
3 Replies
TIMEOUT(1)							   User Commands							TIMEOUT(1)

NAME
timeout - run a command with a time limit SYNOPSIS
timeout [OPTION] DURATION COMMAND [ARG]... timeout [OPTION] DESCRIPTION
Start COMMAND, and kill it if still running after DURATION. Mandatory arguments to long options are mandatory for short options too. --preserve-status exit with the same status as COMMAND, even when the command times out --foreground when not running timeout directly from a shell prompt, allow COMMAND to read from the TTY and get TTY signals; in this mode, children of COMMAND will not be timed out -k, --kill-after=DURATION also send a KILL signal if COMMAND is still running this long after the initial signal was sent -s, --signal=SIGNAL specify the signal to be sent on timeout; SIGNAL may be a name like 'HUP' or a number; see 'kill -l' for a list of signals --help display this help and exit --version output version information and exit DURATION is a floating point number with an optional suffix: 's' for seconds (the default), 'm' for minutes, 'h' for hours or 'd' for days. If the command times out, and --preserve-status is not set, then exit with status 124. Otherwise, exit with the status of COMMAND. If no signal is specified, send the TERM signal upon timeout. The TERM signal kills any process that does not block or catch that signal. It may be necessary to use the KILL (9) signal, since this signal cannot be caught, in which case the exit status is 128+9 rather than 124. BUGS
Some platforms don't currently support timeouts beyond the year 2038. AUTHOR
Written by Padraig Brady. REPORTING BUGS
GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report timeout translation bugs to <http://translationproject.org/team/> COPYRIGHT
Copyright (C) 2017 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO
kill(1) Full documentation at: <http://www.gnu.org/software/coreutils/timeout> or available locally via: info '(coreutils) timeout invocation' GNU coreutils 8.28 January 2018 TIMEOUT(1)
All times are GMT -4. The time now is 09:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy