Foreground sesu SSH with here document


 
Thread Tools Search this Thread
Top Forums Programming Foreground sesu SSH with here document
# 8  
Old 04-27-2012
I've never heard of a shell which doesn't take -s. Even weird things like csh do it. But -- might be less common, though it's luckily optional.

Quote:
Originally Posted by doonan_79
I'm running a Korn shell (ksh) and I think the "-s" switch gave me issues.... are those two dashes required? i.e. the "--" after "-s"? Thanks!
If your shell doesn't take them, leave them out, they're optional.

What the double-dashes do is prevent the shell from interpreting arguments after it as flags like -f or what have you, which could change the behavior of the shell.
# 9  
Old 04-30-2012
Unfortunately none of these fixes my issue. Actually the "-s" switch without the "--" worked for me with my direct (no sesu) command. Here is the working command.

Code:
ssh <targetserver> exec /usr/bin/ksh -s a b c << "EOF"
echo $1 $2 $3
EOF

However once I spice it up and introduce a sesu command into the mix it fails. This is the failing statement:

Code:
ssh <user>@<targetserver> /usr/seos/bin/sesu - <user> -c "/usr/bin/ksh" -s a b c << "EOF"
echo $1 $2 $3
EOF

so the difference is that it must need a different kind of call for the "-c" command switch for sesu I think.... any ideas?

---------- Post updated at 10:46 ---------- Previous update was at 10:40 ----------

NB have tried that with and without exec in addition to "-c"

Code:
ssh <user>@<targetserver> /usr/seos/bin/sesu - <user> -c "exec /usr/bin/ksh -s a b c" << "EOF"
echo $1 $2 $3
EOF

---------- Post updated at 11:03 ---------- Previous update was at 10:46 ----------

OK the "-c" on the sesu seems to remove the need to call "exec". However I'm guessing the "-s", which I intend as a switch on the ksh, is actually trying to be interpreted as part of the sesu..... tried using apostrophes as below but still not working... getting the error: "/bin/su: a: No such file or directory"

(NB being in Korn first to run this code)
Code:
ssh <user>@<targetserver> /usr/seos/bin/sesu - <user> -c '/usr/bin/ksh -s a' << "EOF"
echo $1
EOF

---------- Post updated at 14:29 ---------- Previous update was at 11:03 ----------

OK almost cracked I think - need apostrophes around the whole passed command - E.g.

Code:
ssh <user>@<targetserver> '/usr/seos/bin/sesu - <user> -c "/usr/bin/ksh -s a"' << "EOF"
echo $1
EOF

however..... I find now that I cannot dynamically generate this command. If I pass that whole command string:
Code:
'/usr/seos/bin/sesu - <user> -c "/usr/bin/ksh -s a"'

as a variable $command. Then it doesn't work... if I run it without variable substitution it does work... cannot figure out why - the var does include the speech marks and apostrophes - if you echo it, then it comes out exactly as the command that works when you run it all in one line....

The error btw is as follows:
Code:
sh: /usr/seos/bin/sesu - <user> -c "/usr/bin/ksh -s a": No such file or directory

---------- Post updated at 14:57 ---------- Previous update was at 14:29 ----------

sorted - when passed as a variable the apostrophes are implicit. Finally got it working - thanks for those who input:

Code:
command='/usr/seos/bin/sesu - <user> -c "/usr/bin/ksh -s a"'

ssh <user>@<server> $command

Works very nicely and you can include a here document then as so:

Code:
command='/usr/seos/bin/sesu - <user> -c "/usr/bin/ksh -s a"'

ssh <user>@<server> $command << "EOF"
echo $1
date
EOF

This will then echo "a" out and you can have a nice long list of commands from the here doc to run on the remote box. You can even log it locally as so:

Code:
command='/usr/seos/bin/sesu - <user> -c "/usr/bin/ksh -s a"'

ssh <user>@<server> $command << "EOF" >> <logfile>
echo $1
date
EOF

---------- Post updated at 14:58 ---------- Previous update was at 14:57 ----------

NB QQ I've heard - why setup command as a var?
A: Because then you can generate it as a dynamic statement within a script - very handy!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automatic logon via PUTTY and sesu -

Hi, I need to write a script to automate the logon via putty with Sesu-. can someone help me? thanks in advance (1 Reply)
Discussion started by: austrold
1 Replies

2. Shell Programming and Scripting

ssh uses here-document problem

I try to ssh uses bash script in here-document like this. ssh root@$SERVER <<EOF if ; then service httpd start fi exit EOF But got an error below. maybe the if command causes the problem. Thanks for help. (2 Replies)
Discussion started by: muffle
2 Replies

3. Programming

Background SSH using here document

I'm trying to use Here documents to pass several commands to a remote server over SSH. However I'm having problems. The code is as follows: nohup ssh $i_hostname exec /usr/bin/ksh -s << EOF >> $AS_STOPSAP_LOG & echo $i_instname; ps -ef | grep name | grep ${i_instname} |grep -v grep ... (4 Replies)
Discussion started by: doonan_79
4 Replies

4. Shell Programming and Scripting

Here document inside a here document?

Can we use a here document inside a here document? Something like this ssh user@remotehost << REMOTE sudo vserver vsernamename enter << VSERVER perform actions on vserver. VSERVER REMOTE (6 Replies)
Discussion started by: mnanavati
6 Replies

5. UNIX for Advanced & Expert Users

Bringing a nohup process to foreground

Hi, I have used nohup command to run a process in background. i ran successfully and i exit from that terminal. But when i login for the next time I am not able to see the process but it is working, since I am getting a e-mail alert for error issue. Please let me know how to bring that process... (3 Replies)
Discussion started by: mbguy
3 Replies

6. UNIX for Dummies Questions & Answers

bringing a process to the foreground

If i have a single file i would just press fg but if i have multiple files running in the backgound and want to bring a specific one to the foreground how would i do that? Thanks!! (1 Reply)
Discussion started by: JamieMurry
1 Replies

7. Shell Programming and Scripting

Background and Foreground of a process within a script

I'm not sure if it is even possible but I figured if it was someone here would know how to do it... I am running a script which starts a bunch of processes in the background but there is one process I would like to bring back to the foreground when complete. Unfortunately the process that I... (2 Replies)
Discussion started by: ctruhn
2 Replies

8. Shell Programming and Scripting

ssh and here document

Hi :) how can I use here doc to use ssh? I am facing a problem with the below script: #!/bin/bash ssh hosein@localhost << * 123456 * "123456" is my password Thanks (2 Replies)
Discussion started by: htabesh
2 Replies

9. Shell Programming and Scripting

how to get background job to foreground

hi, i am just wondering that wen we give the following code we make a process run in background...can the viceversa be performed?i.e can this be made foreground again # sleep 75& 21751 # (4 Replies)
Discussion started by: sandilya
4 Replies

10. Shell Programming and Scripting

Execute SAS Foreground

Hi, I am executing the SAS program using Unix script to call SAS program, but i would like to run that SAS program in forground mode, does anyone know what is command. Thanks in advance!! (0 Replies)
Discussion started by: terala
0 Replies
Login or Register to Ask a Question