Sponsored Content
Top Forums Programming Background (nohup * &) SSH command block possible? Post 302631055 by doonan_79 on Friday 27th of April 2012 05:32:18 AM
Old 04-27-2012
A quick, and wonderful response - thank you - one more thing though. How would you run your final version there in the background (so if it's in a script that script can continue on while that code runs?)

Perhaps like this?
Code:
nohup ssh username@host exec /usr/bin/env sh -s "arg1" "arg2" "arg3" <<"EOF" > logfile.log &
echo "First argument is $1"
echo "Second argument is $2"
echo "Third argument is $3"
EOF

Not sure if I really need the nohup and the ampersand ...... have tried the ssh -f option to fork to background but doesn't seem to like that..

---------- Post updated at 21:54 ---------- Previous update was at 21:45 ----------

In Fact I think I have it! Returning to my post syntax updating with your input I have running - awesome!

Code:
nohup ssh -q <targetserver> exec /usr/bin/ksh -s << EOF > <log> &
echo 1
echo 2
date
EOF

Works a treat! No output to my STOUD/screen (thanks to -q option on ssh) and the log is generated locally from commands passed to the remote box using an code block - absolute genuis - many thanks Corona688. I am indebted to you.

---------- Post updated 27-04-12 at 10:19 ---------- Previous update was 26-04-12 at 21:54 ----------

*UPDATE*

I have found now that while this works for simple commands I include a FOR loop within the EOF code-block and it errors as follows (below) - any ideas??

Code:
nohup ssh -q <targetserver> exec /usr/bin/ksh -s << EOF > <log> &
echo 1
echo 2
date
testvar="a b c"
for i in ${testvar}
do
 echo $i
done
EOF

Error is :
Code:
/usr/bin/ksh: syntax error at line X : `newline or ;' unexpected

---------- Post updated at 10:32 ---------- Previous update was at 10:19 ----------

Ah-ha! You can use $() to execute code in a here document. OK so here is ht working fix to that:

Code:
nohup ssh -q <targetserver> exec /usr/bin/ksh -s << EOF > <log> &
echo 1
echo 2
date
$(
testvar="a b c"
for i in ${testvar}
do
 echo $i
done
)
EOF

This User Gave Thanks to doonan_79 For This Post:
 

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
All times are GMT -4. The time now is 08:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy