Sponsored Content
Top Forums Programming Background (nohup * &) SSH command block possible? Post 302631031 by doonan_79 on Thursday 26th of April 2012 04:06:33 PM
Old 04-26-2012
Error Background (nohup * &) SSH command block possible?

Hello,
I am trying to find a way to send several sequential commands via SSH to a remote box in a single command.
Thoughts so far:

1) Can I put them into a function and call the function within the ssh command?

e.g.
Code:
ssh <targetserver> $(functionx)

No - then it calls the function in the shell on the target and does not recognised it.

2) Can I use a command block?

e.g.
Code:
ssh <targetserver> << EOF
echo 1
echo 2
date
EOF

Hmmm - maybe, but I get these messages:
Code:
"Pseudo-terminal will not be allocated because stdin is not a terminal"
(and on target)
"Warning: no access to tty (Bad file descriptor).
Thus no job control in this shell."

Actually then is does run the commands BUT I'm not sure it's solid.
my final target is that I want to run this whole command in the background --- when I try and do this with nohup I still see these errors
E.g.
Code:
nohup ssh <targetserver> << EOF > <log> &
echo 1
echo 2
date
EOF

Code:
"Pseudo-terminal will not be allocated because stdin is not a terminal"
(and on target)
"Warning: no access to tty (Bad file descriptor).
Thus no job control in this shell."

3) Create a shell script on the target and call that...
this option does work but I really want to find a way to centralise this script so that I don't have to stick the second script on every server I want to connect to.


I think it's quite an interesting one - can anyone advise on the best possible method for generating a set of commands to execute on a remote box via ssh; but with one SSH command?

NB It cannot be several SSH commands as I need this to both be run in the background and also for the commands to be sequential.

Thanks in advance!
Jamie Neilan

Last edited by Corona688; 04-26-2012 at 05:12 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

nohup and background process

What is the difference between running a process using nohup and running a process in background ? Please explain (6 Replies)
Discussion started by: srksn
6 Replies

2. Shell Programming and Scripting

ssh a nohup command

I have a script I'm creating to spawn netcat listeners on a remote server for copying files at high speeds. The issue I'm running into is that after running the "nohup nc -l -p 12345 | tar -xvf - &" commands I can't get the remote shell to terminate. I'm not sure if this is working as intended or... (2 Replies)
Discussion started by: headcr4sh
2 Replies

3. UNIX and Linux Applications

nohup and & versus functions

when i have a function definition and function call in my script , i am unable to run my script in background with nohup.. Help me out please..... (3 Replies)
Discussion started by: venugopalsmartb
3 Replies

4. Shell Programming and Scripting

ssh -t and nohup

I have a fairly simple script like so: nohup java -jar program.jar >> log 2>&1 & echo $! > pidfile This works great when using ssh server "script.sh" but not when using ssh -t server "script.sh" The solution I came up with was to call sleep after recording the child pid. My guess at the... (2 Replies)
Discussion started by: croachrose
2 Replies

5. Shell Programming and Scripting

how do i execute nohup and background job inside the korn script for db2

load_cursor_stmt() { ls /db/admin/ddl/rmn01000/load_cursor*.sql|while read file do echo "${file}" `nohup db2 -tvf "$file" \&` done }Error: ------- /admin/ddl/rmn01000/load_cursor5.sql /db/admin/ddl/rmn01000/load_cursor6.sql + read file + echo... (3 Replies)
Discussion started by: Hangman2
3 Replies

6. Shell Programming and Scripting

How to stop nohup which is working background

Please I have run a background script using nohup please tell me way to stop this. Thanks in Advance (4 Replies)
Discussion started by: mumakhij
4 Replies

7. Shell Programming and Scripting

Nohup and background jobs

Hi All, Can someone help me in knowing the exact difference between nohup and &. The definition is quite clear but i only want to know if i run my job using & and in between i hung up my terminal. (10 Replies)
Discussion started by: Uinx_addic
10 Replies

8. UNIX for Dummies Questions & Answers

How do I send output of a background process to a file other than nohup.out?

I have a question. I will be running a background process using nohup and & command at end. I want to send output to a file say myprocess.out. So will this command work? nohup myprocess.ksh > myprocess.out & Thanks in advance guys !!! :) (3 Replies)
Discussion started by: vx04
3 Replies

9. UNIX for Dummies Questions & Answers

Difference between & and nohup &

Hi All, Can anyone please help me understanding what the difference between the below two? 1. script.sh & 2. nohup script.sh & (2 Replies)
Discussion started by: Anupam_Halder
2 Replies

10. UNIX for Dummies Questions & Answers

Sudo ssh with command running in background

I am trying to run a command. This is one of my attempts: for i in fileservera; do ssh -t $i 'sudo ls /';doneThis works, and I see the directories. However, what I want to do now is start a process on the remote server such as /usr/bin/connectproc -standalonesudo /usr/bin/connectproc... (1 Reply)
Discussion started by: newbie2010
1 Replies
SSH-ARGV0(1)						    BSD General Commands Manual 					      SSH-ARGV0(1)

NAME
ssh-argv0 -- replaces the old ssh command-name as hostname handling SYNOPSIS
hostname | user@hostname [-l login_name] [command] hostname | user@hostname [-afgknqstvxACNTX1246] [-b bind_address] [-c cipher_spec] [-e escape_char] [-i identity_file] [-l login_name] [-m mac_spec] [-o option] [-p port] [-F configfile] [-L port:host:hostport] [-R port:host:hostport] [-D port] [command] DESCRIPTION
ssh-argv0 replaces the old ssh command-name as hostname handling. If you link to this script with a hostname then executing the link is equivalent to having executed ssh with that hostname as an argument. All other arguments are passed to ssh and will be processed normally. OPTIONS
See ssh(1). FILES
See ssh(1). AUTHORS
OpenSSH is a derivative of the original and free ssh 1.2.12 release by Tatu Ylonen. Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo de Raadt and Dug Song removed many bugs, re-added newer features and created OpenSSH. Markus Friedl contributed the support for SSH protocol versions 1.5 and 2.0. Jonathan Amery wrote this ssh-argv0 script and the associated documentation. SEE ALSO
ssh(1) Debian Project September 7, 2001 Debian Project
All times are GMT -4. The time now is 06:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy