Shell: Multiple commands via ssh / subshell
Hello,
I have this script:
#!/bin/sh
SP_CONFIG=/home/flindner/spider/spFackrellB2+innerBox.conf
ssh flindner@yoko "ssh yuka << 'ENDSSH'
MESH=`awk '/OUTFILENAME/ {getline; print}' $SP_CONFIG`
ENDSSH"
executed with sh -x
florian@horus ~ % sh -x ./remote_spider_test.sh
+ SP_CONFIG=/home/flindner/spider/spFackrellB2+innerBox.conf
++ awk '/OUTFILENAME/ {getline; print}' /home/flindner/spider/spFackrellB2+innerBox.conf
awk: fatal: cannot open file `/home/flindner/spider/spFackrellB2+innerBox.conf' for reading (No such file or directory)
+ ssh flindner@yoko 'ssh yuka << '\''ENDSSH'\''
MESH=
ENDSSH'
But when I execute the awk command on the machine yuka it works just fine:
flindner@yuka:~> awk '/OUTFILENAME/ {getline; print}' /home/flindner/spider/spFackrellB2+innerBox.conf
meshFackrellB2+innerBox.msh
Therefore I think that somehow awk is being executed on my local machine and not on either one on the remote machines (I would be running on yoko too).
Why is that? How can I execute it on yoko like it was intented? Other commands played just well, I suspect the problem is connected to the subshell execution of awk.
Thanks a lot!
The problem here is that the shell will evaluate the string inside "" before running the command. that means the awk-line will run locally. Try using ' instead of " around the ssh yuka ... ENDSSH. Single quotes will prevent the shell from evaluating anything inside like variables or subshell stuff. Also use $( .. ) instead of ` `, because its more readable
Last edited by seiichiro0185 (2011-09-19 14:11:15)
Similar Messages
-
Exec command via SSH in existing X-Session
Hello,
i want to start the media player app via SSH in an existing X-Session (real display) on the ssh target (ssh user = x-session user, all same machine). I do not mean X-forwarding! After the app is started, i want to disconnect the ssh connection and all should be still running. Any ideas?
Greetings,
SebastianThe difference:
#remote display
ssh user@host DISPLAY=:0 some_command
# although you might assume it get's passed through ssh, it does not and is displayed on the remote machine
ssh -X user@host DISPLAY=:0 some_command
# local display
DISPLAY=:0 ssh -X user@host some_command
Also have a look at the man pages of disown and nohup to learn how to remove the program from your running shell, so you can close the ssh connection.
By the way: export only means, that the variable is exported to the shell. If I run "export TERMINAL=xterm", then until I close the shell, I can for example "echo $TERMINAL" to read "xterm". The shell is always on the host you are connected to. I assume there is a way to bind a remote X server to a DISPLAY (say :100), so you could DISPLAY=:100 to automatically show it on the remote host (or your local host, depending on what machine you sit in front of). I only assume because there is always a way, but I have never tested it or really thought about it. -
Remote command execution via ssh on ips sensor...
I am attempting to execute a command remotely via ssh so that I can collect the information on another host.
ex: ssh -t username@sensor show tech-support
Instead of the output I expect, I receive an error message: Error: Received invalid command line argument.
Is this type of remote command execution supported by the sensor?
Kevin RigginsNot true, i already created scritp to automaticly backup the IPS
-
Total nube to jws, need to run ssh command via web or jws?
Ok So we had a developer that created this application that can basically run ssh commands via jws I believe. Unfortunately he is no longer here. I am wondering how you do this? I know tha commands that are already set up, but I have no idea how to implement it into my project.
I am using Struts 2, Java 5, Weblogic 9.2, Spring
Thanks
orozcomHave a look at:
http://www.jcraft.com/jsch/
basically you'd need a small webstart client to wrap something like the above library. Best thing is to try with a standalone java client first. Once that is working have a look at turning it into a webstart app. -
Cannot start NodeManager Remotly (Via SSH Commands)
Hi all,
we are going to start the node manager of one of the cluster servers via SSH command.
But it is not starting. We can start it directly by log in to that server and run startNodemanager.sh script.
What is the issue?
Thanks,
NirHi are you able to start Node manager using following WLST Command :
startNodeManager(verbos='true',NodeManagerHome='$WL_HOME/common/nodemanager',ListenPort='<PortNo>',ListenAddress='<HostName')
And also can check NodeManager Log files for errors .
Regards
Edited by: TheKop88 on Jun 5, 2013 6:13 PM -
Connection hange while trying to connect via ssh.
Hi all,
I have this problem and i fixed it, just wanted to understand the logic behiend it.
I tried to login to a machine via ssh.
After providing the username and password, the connection hang until you press CTRL -C.
I checked DNS configuration, and some other stuff.
The problem was a NFS entry in the vfstab that was unreachable.
When i removed it, the connection went smoothlly.
My question is, why that entry caused that problem ?
Thanks!At login, the shell runs 'quota -v' to display any over-quota conditions that might exist.
If the NFS mount was not mounted with "noquta", then it will send an RPC request to the server. If the server is down, that request will take 60 seconds to time out. If you have multiple mounts to the server, they might run sequentially.
The login should complete after a minute or so, but most users won't wait that long.
Darren -
TACACS auth working via SSH, but not HTTP (ACS 5.1 / 3560)
Experts,
My switches are able to successfully authenticate user access against ACS 5.1 via SSH with TACACS+, but I am not able to authenticate via HTTPS with TACACS+. I don't even get a log in ACS when attempting to authenticate via HTTPS.
Here is my AAA config, followed by a debug:
aaa new-model
aaa authentication login ACCESS group tacacs+ local
aaa authorization console
aaa authorization config-commands
aaa authorization exec ACCESS group tacacs+
aaa authorization commands 1 Priv1 group tacacs+ none
aaa authorization commands 15 Priv15 group tacacs+ none
aaa authorization network ACCESS group tacacs+
aaa accounting exec ACCESS start-stop group tacacs+
aaa accounting commands 0 ACCESS start-stop group tacacs+
aaa accounting commands 1 ACCESS start-stop group tacacs+
aaa accounting commands 15 ACCESS start-stop group tacacs+
aaa session-id common
ip http authentication aaa login-authentication ACCESS
ip http authentication aaa exec-authorization ACCESS
ip http authentication aaa command-authorization 1 Priv1
ip http authentication aaa command-authorization 15 Priv15
ip http secure-server
no ip http server
tacacs-server host X.X.X.X key 7
tacacs-server timeout 3
tacacs-server directed-request
Debug:
47w4d: HTTP AAA Login-Authentication List name: ACCESS
47w4d: HTTP AAA Exec-Authorization List name: ACCESS
47w4d: HTTP: Authentication failed for level 15
Shell authorization profiles are working in ACS when SSHing to devices (Priv1 and Priv15), and I can't figure out why its not working for HTTPS.
Any ideas?Thank you for your response, here is the debug from the 3560:
BC-3560-48-6-1-1#
48w0d: HTTP AAA Login-Authentication List name: ACCESS
48w0d: HTTP AAA Exec-Authorization List name: ACCESS
48w0d: TPLUS: Queuing AAA Authentication request 0 for processing
48w0d: TPLUS: processing authentication start request id 0
48w0d: TPLUS: Authentication start packet created for 0(varnumd)
48w0d: TPLUS: Using server 10.10.0.16
48w0d: TPLUS(00000000)/0/NB_WAIT/458EDA8: Started 3 sec timeout
48w0d: TPLUS(00000000)/0/NB_WAIT: socket event 2
48w0d: TPLUS(00000000)/0/NB_WAIT: wrote entire 27 bytes request
48w0d: TPLUS(00000000)/0/READ: socket event 1
48w0d: TPLUS(00000000)/0/READ: Would block while reading
48w0d: TPLUS(00000000)/0/READ: socket event 1
48w0d: TPLUS(00000000)/0/READ: read entire 12 header bytes (expect 16 bytes data)
48w0d: TPLUS(00000000)/0/READ: socket event 1
48w0d: TPLUS(00000000)/0/READ: read entire 28 bytes response
48w0d: TPLUS(00000000)/0/458EDA8: Processing the reply packet
48w0d: TPLUS: Received authen response status GET_PASSWORD (8)
48w0d: TPLUS: Queuing AAA Authentication request 0 for processing
48w0d: TPLUS: processing authentication continue request id 0
48w0d: TPLUS: Authentication continue packet generated for 0
48w0d: TPLUS(00000000)/0/WRITE/4332F88: Started 3 sec timeout
48w0d: TPLUS(00000000)/0/WRITE: wrote entire 30 bytes request
48w0d: TPLUS(00000000)/0/READ: socket event 1
48w0d: TPLUS(00000000)/0/READ: read entire 12 header bytes (expect 6 bytes data)
48w0d: TPLUS(00000000)/0/READ: socket event 1
48w0d: TPLUS(00000000)/0/READ: read entire 18 bytes response
48w0d: TPLUS(00000000)/0/4332F88: Processing the reply packet
48w0d: TPLUS: Received authen response status PASS (2)
48w0d: TPLUS: Queuing AAA Authorization request 0 for processing
48w0d: TPLUS: processing authorization request id 0
48w0d: TPLUS: Inappropriate protocol: 25
48w0d: TPLUS: Sending AV service=shell
48w0d: TPLUS: Sending AV cmd*
48w0d: TPLUS: Authorization request created for 0(varnumd)
48w0d: TPLUS: Using server 10.10.0.16
48w0d: TPLUS(00000000)/0/NB_WAIT/4332E18: Started 3 sec timeout
48w0d: TPLUS(00000000)/0/NB_WAIT: socket event 2
48w0d: TPLUS(00000000)/0/NB_WAIT: wrote entire 46 bytes request
48w0d: TPLUS(00000000)/0/READ: socket event 1
48w0d: TPLUS(00000000)/0/READ: Would block while reading
48w0d: TPLUS(00000000)/0/READ: socket event 1
48w0d: TPLUS(00000000)/0/READ: read 0 bytes
48w0d: TPLUS(00000000)/0/READ/4332E18: timed out
48w0d: TPLUS: Inappropriate protocol: 25
48w0d: TPLUS: Sending AV service=shell
48w0d: TPLUS: Sending AV cmd*
48w0d: TPLUS: Authorization request created for 0(varnumd)
48w0d: TPLUS(00000000)/0/READ/4332E18: timed out, clean up
48w0d: TPLUS(00000000)/0/4332E18: Processing the reply packet
48w0d: HTTP: Authentication failed for level 15 -
Hello everyone. Here's my situation:
I'm running Leopard Server 10.5.8.
Recently I made a plist file to put in my users's ~/Library/LaunchAgents folder. It runs an applescript at regular intervals throughout the day. Occasionally I need to stop and relaunch it, which I do using launchctl load ~/Library/LaunchAgents/nameofplist. (or unload, respectively.) This works fine when I'm logged in to the computer using my user's account, which is an admin account. BUT I want to do it via SSH instead. My user's account does not have access to SSH (for a good reason), so I use a special network user account for that. I SSH login remotely via Terminal, and then I type login username using my username and password. Then when I try the launchctl load command, I get this error:
launch_msg(): Socket is not connected
Does anyone know how I can get launchctl to work over SSH?LittleSaint wrote:
Why would applescript be the problem? As long as it was compiled as a script and not an application, it should work just fine from a shell.
Not all shells are equal. An ssh-only connection does not have access to the Aqua user interface.
In Snow Leopard, the behavior seems to be different than before. It tries harder to find an Aqua session to run against. Before, I could just ssh from the Terminal and verify that my command line applications would or would not work. Now, even if I ssh from another account, if my original account is still logged in, I can still launch applications. I have to logout of my original account, login to a new account, ssh back to the original account and then try
[jdaniel@pele:506] ~/Desktop $ osascript testit.scpt
testit.scpt: execution error: An error of type -10810 has occurred. (-10810)
in order to get the desired failure.
Also, you have to actually access something in Aqua before it fails. The above error just comes from activating Address Book. If I take that out and just do 'set thename to "Hello"' it works fine. Of course, I don't know what you can do in AppleScript without telling some Aqua application to do it. -
Newbie - Uploading Podcasts via SSH
Hi,
I am in the process of researching a podcast setup on campus for the Business School. I'd like to know if a Podcast Producer workflow can upload finished podcasts to a file server available only via SSH?
Can files be uploaded using SFTP?
Thanks,
OmairHi,
I have started looking at SCP as an option. What I'd like to do is within Podcast Producer setup custom properties that include my username and password (encrypted) that allow me to log into the server that I need to SCP into.
The destination server is not under my jurisdiction so I have no configuration control over it. I just have a directory I can copy podcasts into.
SCP has a password prompt when I try doing:
scp file1.txt username@destinationHostname:destDir
when I am in the terminal. After I enter the password the file is transferred with no problems.
Is there a way to pass the password within the Podcast Producer workflow or deal with the prompt "automagically"? I have a snippet of Tutorial 10 that I'd like to modify to my needs (the "say" task)
copyToRemoteServer = {
dependsOnTasks = (encode_ipod)
command = "/usr/bin/pcastaction";
arguments = (
shell,
"--basdir=$$Base Directory$$",
"--" // What follows is the command and it's arguments
// Run scp to copy the file over to the remote server
"/usr/bin/scp",
// File to be copied
"$$Content File Basename$$-final.mp4",
// Username Host and Destination Folder
"$$Remote Host Username$$@$$Remote Hostname$$:$$DestFolder$$"
// How do I deal with password? HELP!
What I can't do are the steps outlined in:
http://www.linuxjournal.com/article/8600
Because I don't have the necessary privelages to do anything to the remote machines that I need to SSH/SCP to.
Any ideas?
Thanks,
Omair -
Bug between JRockit and X11 forwarding via ssh
I have encountered what appears to be a bug in the interaction of JRockit with X11 ssh forwarding.
When running any Java GUI application on a remote machine using X11 forwarding via ssh, a variety of problems occur. For example:
--- cut here ---
% mitrion-ide
The program '' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadAtom (invalid Atom parameter)'.
(Details: serial 189 error_code 5 request_code 20 minor_code 0)
(Note to programmers: normally, X errors are reported asynchronously;
that is, you will receive the error a while after causing it.
To debug your program, run it with the --sync command line
option to change this behavior. You can then get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)
--- cut here ---That's the good case. When running the rmmlite application (available at https://rmml.dev.java.net/servlets/ProjectDocumentList?folderID=437&expandFolder=437&folderID=438 ), I experience what appears to be a near-lockup of my local workstation.
Neither of these problems occur if I set my DISPLAY to not use ssh X11 forwarding. Likewise, non-Java applications work just fine with ssh X11 forwarding. Therefore the problem seems to be limited to the Java + ssh X11 forwarding combination.
I have a suitable workaround (i.e. setting the DISPLAY variable to avoid ssh X11 forwarding), but I thought this was worth bringing to BEA's attention. I'd also be curious to know if others have run into similar difficulties.
Here are the configuration details:
Remote X11 client (where applications are hosted)
=================================================
% java -version
java version "1.4.2_12"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_12-b03)
BEA JRockit(R) (build R27.1.0-109-73164-1.4.2_12-20061129-1418-linux-ia32, compiled mode)
% uname -a
Linux earthling 2.6.9-34.ELsmp #1 SMP Fri Feb 24 16:54:53 EST 2006 i686 athlon i386 GNU/Linux
% rpm -qa | grep openssh-server
openssh-server-3.9p1-8.RHEL4.12
This is a vanilla RedHat Linux RHEL 4 Update 3 system, with all other versions of Java removed.
Local workstation (i.e. X11 server)
===================================
% uname -a
FreeBSD somewhere.sgi.com 6.2-RELEASE FreeBSD 6.2-RELEASE #5: Mon Jan 15 08:41:01 CST 2007 [email protected]:/usr/obj/usr/src/sys/somewhere i386
% ssh -v
OpenSSH_4.5p1 FreeBSD-20061110, OpenSSL 0.9.7e-p1 25 Oct 2004
% pkg_info -Ix xorg-server
xorg-server-6.9.0_3 X.Org X server and related programs
Thank you,
Brent CasavantBrent,
it would be nice to know if this problem is specific to the JRockit JDK or
if you also can reproduce it using the corresponding Sun JDK 1.4.2. Please
do also try with a later version such as latest JRockit JDK 5.0.
Thanks
/Robert
<Brent Casavant> wrote in message news:[email protected]...
I have encountered what appears to be a bug in the interaction of JRockit
with X11 ssh forwarding.
When running any Java GUI application on a remote machine using X11
forwarding via ssh, a variety of problems occur. For example:
--- cut here ---
% mitrion-ide
The program '' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadAtom (invalid Atom parameter)'.
(Details: serial 189 error_code 5 request_code 20 minor_code 0)
(Note to programmers: normally, X errors are reported asynchronously;
that is, you will receive the error a while after causing it.
To debug your program, run it with the --sync command line
option to change this behavior. You can then get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)
--- cut here ---That's the good case. When running the rmmlite application (available at
https://rmml.dev.java.net/servlets/ProjectDocumentList?folderID=437&expandFolder=437&folderID=438 )
, I experience what appears to be a near-lockup of my local workstation.
Neither of these problems occur if I set my DISPLAY to not use ssh X11
forwarding. Likewise, non-Java applications work just fine with ssh X11
forwarding. Therefore the problem seems to be limited to the Java + ssh X11
forwarding combination.
I have a suitable workaround (i.e. setting the DISPLAY variable to avoid ssh
X11 forwarding), but I thought this was worth bringing to BEA's attention.
I'd also be curious to know if others have run into similar difficulties.
Here are the configuration details:
Remote X11 client (where applications are hosted)
=================================================
% java -version
java version "1.4.2_12"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_12-b03)
BEA JRockit(R) (build R27.1.0-109-73164-1.4.2_12-20061129-1418-linux-ia32,
compiled mode)
% uname -a
Linux earthling 2.6.9-34.ELsmp #1 SMP Fri Feb 24 16:54:53 EST 2006 i686
athlon i386 GNU/Linux
% rpm -qa | grep openssh-server
openssh-server-3.9p1-8.RHEL4.12
This is a vanilla RedHat Linux RHEL 4 Update 3 system, with all other
versions of Java removed.
Local workstation (i.e. X11 server)
===================================
% uname -a
FreeBSD somewhere.sgi.com 6.2-RELEASE FreeBSD 6.2-RELEASE #5: Mon Jan 15
08:41:01 CST 2007
[email protected]:/usr/obj/usr/src/sys/somewhere i386
% ssh -v
OpenSSH_4.5p1 FreeBSD-20061110, OpenSSL 0.9.7e-p1 25 Oct 2004
% pkg_info -Ix xorg-server
xorg-server-6.9.0_3 X.Org X server and related programs
Thank you,
Brent Casavant -
How to create script that run sudo-command, via automator?
Hi
I'd want to create script to automate one command I need quite often. I just can't get this to work.
I'm not using english OS, but I think this is what I do. In automator I choose Utilities -> Run script
Here's the script I try to run:
sudo "/Library/Application Support/VMware Fusion/boot.sh --restart"
I found some tip to do it like this:
do shell script "sudo /Library/Application Support/VMware Fusion/boot.sh --restart password "pass" with administrator privileges
Where pass is my admin password.
This does not work, either.
Could anybody help me on this?
Thanks...
Tomi Toivonen
Message was edited by: TomiThis is not working. What's wrong?
What's wrong is that the '--restart' is a parameter for boot.sh, and therefore needs to be included within the quotes.
Additionally, the shell uses spaces to divide parameters, so the spaces in the command will make it appear as multiple commands - '/Library/Application', 'Support/VMware' and 'Fusion/boot.sh'. You need to escape them using a backslash:
<pre class=command>do shell script "/Library/Application\ Support/VMware\ Fusion/boot.sh --restart" password "pass" with administrator privileges</pre>
If it's outside of the quotes it would be interpreted as a parameter to 'do shell script' and it won't know what to do with that. -
Accessing Disabled Accounts via ssh
We have user accounts on our OS X Tiger Server where the user has installed a public key into their ~/.ssh/authorized_keys file.
The problem:
If I uncheck "access account" in Workgroup Manager for one of those users, they can still login to the server via ssh, authenticating with their private key.
So, how can I truly disable access to an account that has a key pair installed for ssh?
Mac OS X (10.4.5)Have you tried using WGM to change their login shell to "none"?
-
Do I run a shell script (bsh) via PL/SQL stored procedure?
Hello guys,
Do I run a shell script (bsh) via PL/SQL stored procedure?
For example:
procedure X is
(variables)
begin
-- Read file data
vFileHandle := utl_file.fopen('/mnt/novell/', 'file.txt','r');
exception
when 'INVALID READ FILE' then
(I've to try running script to mount a Novell partition.);
end;
I've to installed Oracle 9.0.1 on Suse Linux.
Please, any ideas or hints ...
Thx and regards.You might be able to us the HOST command, I think you'd have to run it via dbms_sql, check this page for more details, not sure if it'll be of help but its worth a try..
http://otn.oracle.com/docs/products/oracle8i/doc_library/817_doc/server.817/a82950/ch8.htm
Cheers
Rob -
Remove a proxy setting via ssh or ARD?
Is it possible to delete a proxy config from the command line? I have looked at scutil, networksetup, ifconfig, ipconfig, systemsetup and scselet command, some of which will SHOW me a proxy config which is helpful, but I need to remove the proxy settings altogether.
Im going to be removing our proxy server this year (no more proxy), and will need to remove all proxy settings from all my Mac systems. Id like to script it somehow, or at least be able to do it remotely via ssh or ARD.I dont think it works in Leopard. For example, when I type the related command:
"sudo networksetup -getwebproxy Ethernet"
I get the following answer:
Enabled: No
Server:
Port: 0
Authenticated Proxy Enabled: 0
(even though the proxy is configured and working and can be tested. Thus, networksetup doesnt have a clue about the proxy server configs in the Network system prefs pane.)
The "scutil --proxy" command does show me my current proxy configurations (similar to what the Network pres pane shows), but the command doesnt allow me to disable or delete them. Example:
<dictionary> {
ExceptionsList : <array> {
0 : *.local
1 : 169.254/16
ProxyAutoConfigURLString : http://wpad/proxy.pac
FTPPassive : 1
ProxyAutoConfigEnable : 1
HTTPEnable : 0
(I get the same response regardless if I type
"networksetup -setwebproxystate "Ethernet" off"
or
"networksetup -setwebproxystate "Ethernet" on" -
I can not connect via SSH to a MacBook (the internal home network)
Hi all! There is an internal home network of three computers and Wi-Fi router. On the router and the computers with Win7 via SSH I go (with a MacBook) without problems, but on a MacBook with any other computer can not enter via SSH. What could be wrong?
ssh -v -v -v [email protected]
Do this once for a working system,
And once for a broken system.
Compare the output and see what is says where the broken system changes radically from the working system.
Also on the destination system look in the /var/log/secure.log file for sshd entries to see if the destination system is rejecting your connection and for what reason.
It is possible on the destination system to get even more information by changing the /etc/sshd_config file entry
#LogLevel INFO
to
LogLevel DEBUG3
then issue the command
sudo kill -HUP `/var/run/sshd.pid` # reload sshd configuration parameters
Maybe you are looking for
-
Here's the issue-I have two iTunes accounts, yet account #1 always comes up when I want to update my apps. This occurs even when account #2 is logged in and has been synced from desktop to iPad. Additionally,Account #2 is logged in on the iPad and ye
-
How to disable multiple users logging
hi I posted a question earlier and googled the same question but found no fruitfull solutions. http://forum.java.sun.com/thread.jspa?threadID=748292 Rather than solving the problem i am looking for a way around it. Is it possible to Allow just one us
-
Photos appear in screen saver but i can't find them!
I have my screesaver set to show photos from users/user/pictures. the only items in that folder are an empty photo booth folder and my iphoto library. after organizing my photos and events, pictures i'm not aware of are showing up in my screen saver.
-
How do you get cursor to move in Dreamweaver CS5?
Im trying to get the cursor to move to the right or go up and down but it stays to the left. Im new to dreamweaver so any advice would be much appreciated. Thanks in advance
-
Sorting a grid with CollapseLevel = 1
hi i have a grid in my form, and i use a DataTable to fill up that grid. My sql commando was 2 fields in order by. And it works fine. They are represented by [COL 1] and [COL 5] DESC. COL 1 ! COL 2 ! COL 3 ! COL 4 ! COL 5 01 Ex ! 00001 ! 00001 ! 0000